Add draft NEWS entries
[xapian.git] / xapian-core / net / replicatetcpclient.cc
bloba5e1bcc55eb5234a6ae8df1e2173a37e613f5b87
1 /** @file
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 #include <config.h>
23 #include "replicatetcpclient.h"
25 #include "api/replication.h"
27 #include "socket_utils.h"
28 #include "tcpclient.h"
30 using namespace std;
32 ReplicateTcpClient::ReplicateTcpClient(const string & hostname, int port,
33 double timeout_connect,
34 double socket_timeout)
35 : socket(open_socket(hostname, port, timeout_connect)),
36 remconn(-1, socket)
38 set_socket_timeouts(socket, socket_timeout);
41 int
42 ReplicateTcpClient::open_socket(const string & hostname, int port,
43 double timeout_connect)
45 return TcpClient::open_socket(hostname, port, timeout_connect, false);
48 void
49 ReplicateTcpClient::update_from_master(const std::string & path,
50 const std::string & masterdb,
51 Xapian::ReplicationInfo & info,
52 double reader_close_time,
53 bool force_copy)
55 Xapian::DatabaseReplica replica(path);
56 remconn.send_message('R',
57 force_copy ? string() : replica.get_revision_info(),
58 0.0);
59 remconn.send_message('D', masterdb, 0.0);
60 replica.set_read_fd(socket);
61 info.clear();
62 bool more;
63 do {
64 Xapian::ReplicationInfo subinfo;
65 more = replica.apply_next_changeset(&subinfo, reader_close_time);
66 info.changeset_count += subinfo.changeset_count;
67 info.fullcopy_count += subinfo.fullcopy_count;
68 if (subinfo.changed)
69 info.changed = true;
70 } while (more);
73 ReplicateTcpClient::~ReplicateTcpClient()
75 remconn.shutdown();