00001
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include <config.h>
00022
00023 #include "replicatetcpclient.h"
00024
00025 #include "replication.h"
00026
00027 #include "tcpclient.h"
00028 #include "utils.h"
00029
00030 using namespace std;
00031
00032 ReplicateTcpClient::ReplicateTcpClient(const string & hostname, int port,
00033 double timeout_connect)
00034 : socket(open_socket(hostname, port, timeout_connect)),
00035 remconn(-1, socket)
00036 {
00037 }
00038
00039 int
00040 ReplicateTcpClient::open_socket(const string & hostname, int port,
00041 double timeout_connect)
00042 {
00043 return TcpClient::open_socket(hostname, port, timeout_connect, false);
00044 }
00045
00046 void
00047 ReplicateTcpClient::update_from_master(const std::string & path,
00048 const std::string & masterdb,
00049 Xapian::ReplicationInfo & info,
00050 double reader_close_time)
00051 {
00052 Xapian::DatabaseReplica replica(path);
00053 remconn.send_message('R', replica.get_revision_info(), 0.0);
00054 remconn.send_message('D', masterdb, 0.0);
00055 replica.set_read_fd(socket);
00056 info.clear();
00057 bool more;
00058 do {
00059 Xapian::ReplicationInfo subinfo;
00060 more = replica.apply_next_changeset(&subinfo, reader_close_time);
00061 info.changeset_count += subinfo.changeset_count;
00062 info.fullcopy_count += subinfo.fullcopy_count;
00063 if (subinfo.changed)
00064 info.changed = true;
00065 } while (more);
00066 }
00067
00068 ReplicateTcpClient::~ReplicateTcpClient()
00069 {
00070 remconn.do_close(true);
00071 }