00001
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include <config.h>
00023
00024 #include "replicatetcpserver.h"
00025
00026 #include <xapian.h>
00027
00028 #include "gnu_getopt.h"
00029
00030 #include <cstdlib>
00031 #include <iostream>
00032
00033 using namespace std;
00034
00035 #define PROG_NAME "xapian-replicate-server"
00036 #define PROG_DESC "Service database replication requests from clients"
00037
00038 #define OPT_HELP 1
00039 #define OPT_VERSION 2
00040
00041 static void show_usage() {
00042 cout << "Usage: "PROG_NAME" [OPTIONS] DATABASE_PARENT_DIRECTORY\n\n"
00043 "Options:\n"
00044 " -I, --interface=ADDR listen on interface ADDR\n"
00045 " -p, --port=PORT port to listen on\n"
00046 " -o, --one-shot serve a single connection and exit\n"
00047 " --help display this help and exit\n"
00048 " --version output version information and exit" << endl;
00049 }
00050
00051 int
00052 main(int argc, char **argv)
00053 {
00054 const char * opts = "I:p:o";
00055 const struct option long_opts[] = {
00056 {"interface", required_argument, 0, 'I'},
00057 {"port", required_argument, 0, 'p'},
00058 {"one-shot", no_argument, 0, 'o'},
00059 {"help", no_argument, 0, OPT_HELP},
00060 {"version", no_argument, 0, OPT_VERSION},
00061 {NULL, 0, 0, 0}
00062 };
00063
00064 string host;
00065 int port = 0;
00066
00067 bool one_shot = false;
00068
00069 int c;
00070 while ((c = gnu_getopt_long(argc, argv, opts, long_opts, 0)) != -1) {
00071 switch (c) {
00072 case 'I':
00073 host.assign(optarg);
00074 break;
00075 case 'p':
00076 port = atoi(optarg);
00077 break;
00078 case 'o':
00079 one_shot = true;
00080 break;
00081 case OPT_HELP:
00082 cout << PROG_NAME" - "PROG_DESC"\n\n";
00083 show_usage();
00084 exit(0);
00085 case OPT_VERSION:
00086 cout << PROG_NAME" - "PACKAGE_STRING << endl;
00087 exit(0);
00088 default:
00089 show_usage();
00090 exit(1);
00091 }
00092 }
00093
00094 if (argc - optind != 1) {
00095 show_usage();
00096 exit(1);
00097 }
00098
00099
00100 string dbpath(argv[optind]);
00101
00102 try {
00103 ReplicateTcpServer server(host, port, dbpath);
00104 if (one_shot) {
00105 server.run_once();
00106 } else {
00107 server.run();
00108 }
00109 } catch (const Xapian::Error &error) {
00110 cerr << argv[0] << ": " << error.get_description() << endl;
00111 exit(1);
00112 }
00113 }