[honey] Fix portability to systems without pread()
[xapian.git] / xapian-core / net / remotetcpclient.cc
blob62f0f0a7bf75756275290d88ca706cc8082c5a9b
1 /** @file remotetcpclient.cc
2 * @brief TCP/IP socket based RemoteDatabase implementation
3 */
4 /* Copyright (C) 2008,2010 Olly Betts
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation; either version 2 of the
9 * License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21 #include <config.h>
23 #include "remotetcpclient.h"
25 #include <xapian/error.h>
27 #include "str.h"
28 #include "tcpclient.h"
30 using namespace std;
32 int
33 RemoteTcpClient::open_socket(const string & hostname, int port,
34 double timeout_connect)
36 // If TcpClient::open_socket() throws, fill in the context.
37 try {
38 return TcpClient::open_socket(hostname, port, timeout_connect, true);
39 } catch (const Xapian::NetworkTimeoutError & e) {
40 throw Xapian::NetworkTimeoutError(e.get_msg(), get_tcpcontext(hostname, port),
41 e.get_error_string());
42 } catch (const Xapian::NetworkError & e) {
43 throw Xapian::NetworkError(e.get_msg(), get_tcpcontext(hostname, port),
44 e.get_error_string());
48 string
49 RemoteTcpClient::get_tcpcontext(const string & hostname, int port)
51 string result("remote:tcp(");
52 result += hostname;
53 result += ':';
54 result += str(port);
55 result += ')';
56 return result;
59 RemoteTcpClient::~RemoteTcpClient()
61 do_close();