1 /** @file xapian-progsrv.cc
2 * @brief Remote server for use with ProgClient.
4 /* Copyright (C) 2002,2003,2006,2007,2008,2010,2011 Olly Betts
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (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
23 #include "net/remoteserver.h"
25 #include "gnu_getopt.h"
33 #define PROG_NAME "xapian-progsrv"
34 #define PROG_DESC "Piped server for use with Xapian's remote backend"
39 static const char * opts
= "t:w";
40 static const struct option long_opts
[] = {
41 {"timeout", required_argument
, 0, 't'},
42 {"writable", no_argument
, 0, 'w'},
43 {"help", no_argument
, 0, OPT_HELP
},
44 {"version", no_argument
, 0, OPT_VERSION
},
48 static void show_usage() {
49 cout
<< "Usage: " PROG_NAME
" [OPTIONS] DATABASE_DIRECTORY...\n\n"
51 " --timeout MSECS set timeout\n"
52 " --writable allow updates (only one database directory allowed)\n"
53 " --help display this help and exit\n"
54 " --version output version information and exit" << endl
;
57 int main(int argc
, char **argv
)
59 double timeout
= 60.0;
60 bool writable
= false;
61 bool syntax_error
= false;
64 while ((c
= gnu_getopt_long(argc
, argv
, opts
, long_opts
, NULL
)) != -1) {
67 cout
<< PROG_NAME
" - " PROG_DESC
"\n\n";
71 cout
<< PROG_NAME
" - " PACKAGE_STRING
<< endl
;
74 timeout
= atoi(optarg
) * 1e-3;
84 if (syntax_error
|| optind
== argc
) {
89 if (writable
&& (argc
- optind
) != 1) {
90 cerr
<< "Error: only one database directory allowed with '--writable'."
95 /* Unlike xapian-tcpsrv, xapian-progsrv only has a single 'connection'
96 * which is established immediately. So, there is no point in attempting
97 * to open the database(s) to check they work - if they can't be opened the
98 * client will get an exception right away anyway.
100 vector
<string
> dbnames(argv
+ optind
, argv
+ argc
);
103 // We communicate with the client via stdin (fd 0) and stdout (fd 1).
104 // Note that RemoteServer closes these fds.
105 RemoteServer
server(dbnames
, 0, 1, timeout
, timeout
, writable
);
107 // If you have defined your own weighting scheme, register it here
109 // server.register_weighting_scheme(FooWeight());
113 /* Catch and ignore any exceptions thrown by RemoteServer, since the
114 * RemoteServer will have passed the error to the client to be rethrown
117 * Our stdout is the (now closed) communication channel to the client,
118 * and our stderr is probably a closed fd so we don't have anywhere to
119 * send error messages to anyway!