xapian-core  1.4.27
remotetcpclient.cc
Go to the documentation of this file.
1 
4 /* Copyright (C) 2008,2010 Olly Betts
5  *
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.
10  *
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.
15  *
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
19  */
20 
21 #include <config.h>
22 
23 #include "remotetcpclient.h"
24 
25 #include <xapian/error.h>
26 
27 #include "str.h"
28 #include "tcpclient.h"
29 
30 using namespace std;
31 
32 int
33 RemoteTcpClient::open_socket(const string & hostname, int port,
34  double timeout_connect)
35 {
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());
45  }
46 }
47 
48 string
49 RemoteTcpClient::get_tcpcontext(const string & hostname, int port)
50 {
51  string result("remote:tcp(");
52  result += hostname;
53  result += ':';
54  result += str(port);
55  result += ')';
56  return result;
57 }
58 
60 {
61  try {
62  do_close();
63  } catch (...) {
64  }
65 }
Open a TCP connection to a server.
Indicates a timeout expired while communicating with a remote database.
Definition: error.h:845
const std::string & get_msg() const
Message giving details of the error, intended for human consumption.
Definition: error.h:122
STL namespace.
Convert types to std::string.
TCP/IP socket based RemoteDatabase implementation.
Hierarchy of classes which Xapian can throw as exceptions.
~RemoteTcpClient()
Destructor.
string str(int value)
Convert int to std::string.
Definition: str.cc:90
int open_socket(const std::string &hostname, int port, double timeout_connect, bool tcp_nodelay)
Attempt to open a TCP/IP socket connection to a server.
Definition: tcpclient.cc:55
const char * get_error_string() const
Returns any system error string associated with this exception.
Definition: error.cc:50
Indicates a problem communicating with a remote database.
Definition: error.h:803
static int open_socket(const std::string &hostname, int port, double timeout_connect)
Attempt to open a TCP/IP socket connection to xapian-tcpsrv.
static std::string get_tcpcontext(const std::string &hostname, int port)
Get a context string for use when constructing Xapian::NetworkError.