2 * @brief TCP/IP socket based RemoteDatabase implementation
4 /* Copyright (C) 2007,2008,2010,2011,2014,2024 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 #ifndef XAPIAN_INCLUDED_REMOTETCPCLIENT_H
22 #define XAPIAN_INCLUDED_REMOTETCPCLIENT_H
24 #include "backends/remote/remote-database.h"
25 #include "socket_utils.h"
28 #include <string_view>
31 # define SOCKET_INITIALIZER_MIXIN private WinsockInitializer,
33 # define SOCKET_INITIALIZER_MIXIN
36 /** TCP/IP socket based RemoteDatabase implementation.
38 * Connects via TCP/IP to an instance of xapian-tcpsrv.
40 class RemoteTcpClient
: SOCKET_INITIALIZER_MIXIN
public RemoteDatabase
{
41 /// Don't allow assignment.
42 void operator=(const RemoteTcpClient
&);
44 /// Don't allow copying.
45 RemoteTcpClient(const RemoteTcpClient
&);
47 /** Attempt to open a TCP/IP socket connection to xapian-tcpsrv.
49 * Connect to xapian-tcpsrv running on port @a port of host @a hostname.
50 * Give up trying to connect after @a timeout_connect seconds.
52 * @return A std::pair containing the file descriptor for the connection
53 * to the child process and a context string to return with any
56 * Note: this method is called early on during class construction before
57 * any member variables or even the base class have been initialised.
58 * To help avoid accidentally trying to use member variables or call other
59 * methods which do, this method has been deliberately made "static".
61 static std::pair
<int, std::string
> open_socket(std::string_view hostname
,
63 double timeout_connect
);
68 * Attempts to open a TCP/IP connection to xapian-tcpsrv running on port
69 * @a port of host @a hostname.
71 * @param timeout_connect Timeout for trying to connect (in seconds).
72 * @param timeout Timeout during communication after successfully
73 * connecting (in seconds).
74 * @param writable Is this a WritableDatabase?
75 * @param flags Xapian::DB_RETRY_LOCK or 0.
77 RemoteTcpClient(std::string_view hostname
, int port
,
78 double timeout_
, double timeout_connect
, bool writable
,
80 : RemoteDatabase(open_socket(hostname
, port
, timeout_connect
),
81 timeout_
, writable
, flags
) { }
87 #endif // XAPIAN_INCLUDED_REMOTETCPCLIENT_H