xapian-core  2.0.0
tcpserver.h
Go to the documentation of this file.
1 
4 /* Copyright (C) 2007,2008,2023 Olly Betts
5  *
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.
10  *
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.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, see
18  * <https://www.gnu.org/licenses/>.
19  */
20 
21 #ifndef XAPIAN_INCLUDED_TCPSERVER_H
22 #define XAPIAN_INCLUDED_TCPSERVER_H
23 
24 #ifdef __WIN32__
25 # include "socket_utils.h"
26 # define SOCKET_INITIALIZER_MIXIN : private WinsockInitializer
27 #else
28 # define SOCKET_INITIALIZER_MIXIN
29 #endif
30 
31 #include <xapian/visibility.h>
32 
33 #include <string>
34 
38  TcpServer& operator=(const TcpServer&) = delete;
39 
41  TcpServer(const TcpServer&) = delete;
42 
44  int listener;
45 
46  protected:
48  bool verbose;
49 
53 
54  public:
64  TcpServer(const std::string& host, int port, bool tcp_nodelay,
65  bool verbose_);
66 
74 
81  void run();
82 
84  void run_once();
85 
87  bool get_verbose() const { return verbose; }
88 
90  virtual void handle_one_connection(int socket) = 0;
91 };
92 
93 #endif // XAPIAN_INCLUDED_TCPSERVER_H
TCP/IP replication client class.
TcpServer(const std::string &host, int port, bool tcp_nodelay, bool verbose_)
Construct a TcpServer and start listening for connections.
int accept_connection()
Accept a connection and return the file descriptor for it.
TcpServer & operator=(const TcpServer &)=delete
Don't allow assignment.
bool verbose
Should we produce output when connections are made or lost?
Definition: tcpserver.h:48
virtual void handle_one_connection(int socket)=0
Handle a single connection on an already connected socket.
void run_once()
Accept a single connection, service requests on it, then stop.
void run()
Accept connections and service requests indefinitely.
bool get_verbose() const
Should we produce output when connections are made or lost?
Definition: tcpserver.h:87
TcpServer(const TcpServer &)=delete
Don't allow copying.
int listener
The socket we're listening on.
Definition: tcpserver.h:44
Socket handling utilities.
Define XAPIAN_VISIBILITY_* macros.
#define XAPIAN_VISIBILITY_DEFAULT
Definition: visibility.h:28
#define XAPIAN_VISIBILITY_INTERNAL
Definition: visibility.h:29
static int verbose
Definition: xapian-delve.cc:46