[honey] Fix portability to systems without pread()
[xapian.git] / xapian-core / net / remotetcpserver.h
blobfde18b815e1fda7eb36ad8ede819bf037271c7e7
1 /** @file remotetcpserver.h
2 * @brief TCP/IP socket based server for RemoteDatabase.
3 */
4 /* Copyright (C) 2007,2008,2010,2015 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_REMOTETCPSERVER_H
22 #define XAPIAN_INCLUDED_REMOTETCPSERVER_H
24 #include "tcpserver.h"
26 #include <xapian/database.h>
27 #include <xapian/registry.h>
28 #include <xapian/visibility.h>
30 #include <string>
31 #include <vector>
33 /** TCP/IP socket based server for RemoteDatabase.
35 * This class implements the server used by xapian-tcpsrv.
37 class XAPIAN_VISIBILITY_DEFAULT RemoteTcpServer : public TcpServer {
38 /// Don't allow assignment.
39 void operator=(const RemoteTcpServer &);
41 /// Don't allow copying.
42 RemoteTcpServer(const RemoteTcpServer &);
44 /** Paths to the databases we will open.
46 * Contains exactly one entry if writable, and at least one if not.
48 const std::vector<std::string> dbpaths;
50 /** Is this a WritableDatabase? */
51 bool writable;
53 /** Timeout between messages during a single operation (in seconds). */
54 double active_timeout;
56 /** Timeout between operations (in seconds). */
57 double idle_timeout;
59 /** Registry used for (un)serialisation. */
60 Xapian::Registry reg;
62 /** Accept a connection and return the filedescriptor for it. */
63 int accept_connection();
65 public:
66 /** Construct a RemoteTcpServer for a Database and start listening for
67 * connections.
69 * @param dbpaths_ The path(s) to the database(s) we should open.
70 * @param host The hostname or address for the interface to listen on
71 * (or "" to listen on all interfaces).
72 * @param port The TCP port number to listen on.
73 * @param active_timeout Timeout between messages during a single
74 * operation (in seconds).
75 * @param idle_timeout Timeout between operations (in seconds).
76 * @param writable Should we open the DB for writing?
77 * @param verbose Should we produce output when connections are
78 * made or lost?
80 RemoteTcpServer(const std::vector<std::string> &dbpaths_,
81 const std::string &host, int port,
82 double active_timeout, double idle_timeout,
83 bool writable, bool verbose);
85 /// Set the registry used for (un)serialisation.
86 void set_registry(const Xapian::Registry & reg_) { reg = reg_; }
88 /** Handle a single connection on an already connected socket.
90 * This method may be called by multiple threads.
92 void handle_one_connection(int socket);
95 #endif // XAPIAN_INCLUDED_REMOTETCPSERVER_H