[honey] Fix portability to systems without pread()
[xapian.git] / xapian-core / net / replicatetcpclient.h
bloba4a6fbb8badd075641db63f04b28e416ca135e3a
1 /** @file replicatetcpclient.h
2 * @brief TCP/IP replication client class.
3 */
4 /* Copyright (C) 2008,2010,2011,2015 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_REPLICATETCPCLIENT_H
22 #define XAPIAN_INCLUDED_REPLICATETCPCLIENT_H
24 #include "remoteconnection.h"
26 #include "xapian/visibility.h"
27 #include "api/replication.h"
29 #ifdef __WIN32__
30 # define SOCKET_INITIALIZER_MIXIN : private WinsockInitializer
31 #else
32 # define SOCKET_INITIALIZER_MIXIN
33 #endif
35 /// TCP/IP replication client class.
36 class XAPIAN_VISIBILITY_DEFAULT ReplicateTcpClient SOCKET_INITIALIZER_MIXIN {
37 /// Don't allow assignment.
38 void operator=(const ReplicateTcpClient &);
40 /// Don't allow copying.
41 ReplicateTcpClient(const ReplicateTcpClient &);
43 /// The socket fd.
44 int socket;
46 /// Write-only connection to the server.
47 RemoteConnection remconn;
49 /** Attempt to open a TCP/IP socket connection to a replication server.
51 * Connect to replication server running on port @a port of host @a hostname.
52 * Give up trying to connect after @a timeout_connect seconds.
54 * Note: this method is called early on during class construction before
55 * any member variables or even the base class have been initialised.
56 * To help avoid accidentally trying to use member variables or call other
57 * methods which do, this method has been deliberately made "static".
59 XAPIAN_VISIBILITY_INTERNAL
60 static int open_socket(const std::string & hostname, int port,
61 double timeout_connect);
63 public:
64 /** Constructor.
66 * Connect to replication server running on port @a port of host @a hostname.
67 * Give up trying to connect after @a timeout_connect seconds.
69 * @param timeout_connect Timeout for trying to connect (in seconds).
70 * @param socket_timeout Socket timeout (in seconds); 0 for no timeout.
72 ReplicateTcpClient(const std::string & hostname, int port,
73 double timeout_connect, double socket_timeout);
75 void update_from_master(const std::string & path,
76 const std::string & remotedb,
77 Xapian::ReplicationInfo & info,
78 double reader_close_time,
79 bool force_copy);
81 /** Destructor. */
82 ~ReplicateTcpClient();
85 #endif // XAPIAN_INCLUDED_REPLICATETCPCLIENT_H