[honey] Fix portability to systems without pread()
[xapian.git] / xapian-core / net / progclient.h
blob5567e558a63fe6f17c51967ba9eb346df51743ca
1 /** @file progclient.h
2 * @brief Implementation of RemoteDatabase using a spawned server.
3 */
4 /* Copyright (C) 2007,2010,2011,2014 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 #ifndef XAPIAN_INCLUDED_PROGCLIENT_H
22 #define XAPIAN_INCLUDED_PROGCLIENT_H
24 #include <sys/types.h>
26 #include "backends/remote/remote-database.h"
28 /** Implementation of RemoteDatabase using a spawned server.
30 * ProgClient spawns a child process to connect to the server - for example,
31 * an ssh command to run the server on a remote host. Communication with the
32 * child process is via a pipe.
34 class ProgClient : public RemoteDatabase {
35 /// Don't allow assignment.
36 void operator=(const ProgClient &);
38 /// Don't allow copying.
39 ProgClient(const ProgClient &);
41 #ifndef __WIN32__
42 /// Process id of the child process.
43 pid_t pid;
44 #endif
46 /** Start the child process.
48 * @param progname The program used to create the connection.
49 * @param args Any arguments to the program.
50 * @param pid Reference to store the pid of the child process in.
52 * @return filedescriptor for reading from/writing to the child process.
54 * Note: this method is called early on during class construction before
55 * any member variables or even the base class have been initialised.
56 * To help avoid accidentally trying to use member variables, this method
57 * has been deliberately made "static".
59 static int run_program(const std::string &progname,
60 const std::string &args
61 #ifndef __WIN32__
62 , pid_t &pid
63 #endif
66 /** Generate context string for Xapian::Error exception objects.
68 * @param progname The program used to create the connection.
69 * @param args Any arguments to the program.
71 * Note: this method is used from constructors so has been made static to
72 * avoid problems with trying to use uninitialised member variables. In
73 * particular, it can't be made a virtual method of the base class.
75 static std::string get_progcontext(const std::string &progname,
76 const std::string &args);
78 public:
79 /** Constructor.
81 * @param progname The program used to create the connection.
82 * @param args Any arguments to the program.
83 * @param timeout Timeout for communication (in seconds).
84 * @param writable Is this a WritableDatabase?
85 * @param flags Xapian::DB_RETRY_LOCK or 0.
87 ProgClient(const std::string &progname,
88 const std::string &arg,
89 double msecs_timeout,
90 bool writable,
91 int flags);
93 /** Destructor. */
94 ~ProgClient();
97 #endif // XAPIAN_INCLUDED_PROGCLIENT_H