00001
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef XAPIAN_INCLUDED_TCPSERVER_H
00022 #define XAPIAN_INCLUDED_TCPSERVER_H
00023
00024 #ifdef __WIN32__
00025 # include "remoteconnection.h"
00026 # define SOCKET_INITIALIZER_MIXIN : private WinsockInitializer
00027 #else
00028 # define SOCKET_INITIALIZER_MIXIN
00029 #endif
00030
00031 #if defined __CYGWIN__ || defined __WIN32__
00032 # include "safewindows.h"
00033 #endif
00034
00035 #include <xapian/visibility.h>
00036
00037 #include <string>
00038
00043 class XAPIAN_VISIBILITY_DEFAULT TcpServer SOCKET_INITIALIZER_MIXIN {
00045 void operator=(const TcpServer &);
00046
00048 TcpServer(const TcpServer &);
00049
00050 #if defined __CYGWIN__ || defined __WIN32__
00052 HANDLE mutex;
00053 #endif
00054
00056 int listen_socket;
00057
00065 static int get_listening_socket(const std::string & host, int port,
00066 bool tcp_nodelay
00067 #if defined __CYGWIN__ || defined __WIN32__
00068 , HANDLE &mutex
00069 #endif
00070 );
00071
00072 protected:
00074 bool verbose;
00075
00077 int accept_connection();
00078
00079 public:
00089 TcpServer(const std::string &host, int port, bool tcp_nodelay,
00090 bool verbose);
00091
00093 virtual ~TcpServer();
00094
00101 void run();
00102
00104 void run_once();
00105
00107 virtual void handle_one_connection(int socket) = 0;
00108 };
00109
00110 #endif // XAPIAN_INCLUDED_TCPSERVER_H