Reimplement Language Modelling weights
[xapian.git] / xapian-core / bin / xapian-replicate-server.cc
blob7d32170c0142fafd56b35bc171f36c801f3d7bcb
1 /** @file
2 * @brief Service database replication requests from clients.
3 */
4 /* Copyright (C) 2008,2011 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
19 * USA
22 #include <config.h>
24 #include "net/replicatetcpserver.h"
26 #include <xapian.h>
28 #include "gnu_getopt.h"
29 #include "parseint.h"
31 #include <cstdlib>
32 #include <iostream>
34 using namespace std;
36 #define PROG_NAME "xapian-replicate-server"
37 #define PROG_DESC "Service database replication requests from clients"
39 #define OPT_HELP 1
40 #define OPT_VERSION 2
42 static void show_usage() {
43 cout << "Usage: " PROG_NAME " [OPTIONS] DATABASE_PARENT_DIRECTORY\n\n"
44 "Options:\n"
45 " -I, --interface=ADDR listen on interface ADDR\n"
46 " -p, --port=PORT port to listen on\n"
47 " -o, --one-shot serve a single connection and exit\n"
48 " --help display this help and exit\n"
49 " --version output version information and exit\n";
52 int
53 main(int argc, char **argv)
55 const char * opts = "I:p:o";
56 static const struct option long_opts[] = {
57 {"interface", required_argument, 0, 'I'},
58 {"port", required_argument, 0, 'p'},
59 {"one-shot", no_argument, 0, 'o'},
60 {"help", no_argument, 0, OPT_HELP},
61 {"version", no_argument, 0, OPT_VERSION},
62 {NULL, 0, 0, 0}
65 string host;
66 int port = 0;
68 bool one_shot = false;
70 int c;
71 while ((c = gnu_getopt_long(argc, argv, opts, long_opts, 0)) != -1) {
72 switch (c) {
73 case 'I':
74 host.assign(optarg);
75 break;
76 case 'p':
77 if (!parse_signed(optarg, port) ||
78 (port < 1 || port > 65535)) {
79 cerr << "Error: must specify a valid port number "
80 "(between 1 and 65535). \n";
81 exit(1);
83 break;
84 case 'o':
85 one_shot = true;
86 break;
87 case OPT_HELP:
88 cout << PROG_NAME " - " PROG_DESC "\n\n";
89 show_usage();
90 exit(0);
91 case OPT_VERSION:
92 cout << PROG_NAME " - " PACKAGE_STRING "\n";
93 exit(0);
94 default:
95 show_usage();
96 exit(1);
100 if (argc - optind != 1) {
101 show_usage();
102 exit(1);
105 // Path to the database to create/update.
106 string dbpath(argv[optind]);
108 try {
109 ReplicateTcpServer server(host, port, dbpath);
110 if (one_shot) {
111 server.run_once();
112 } else {
113 server.run();
115 } catch (const Xapian::Error &error) {
116 cerr << argv[0] << ": " << error.get_description() << '\n';
117 exit(1);