common/tcpserver.h

Go to the documentation of this file.
00001 
00004 /* Copyright (C) 2007 Olly Betts
00005  *
00006  * This program is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU General Public License as
00008  * published by the Free Software Foundation; either version 2 of the
00009  * License, or (at your option) any later version.
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with this program; if not, write to the Free Software
00018  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
00019  */
00020 
00021 #ifndef XAPIAN_INCLUDED_TCPSERVER_H
00022 #define XAPIAN_INCLUDED_TCPSERVER_H
00023 
00024 #include <xapian/database.h>
00025 #include <xapian/visibility.h>
00026 
00027 #ifdef __WIN32__
00028 # include "remoteconnection.h"
00029 # define SOCKET_INITIALIZER_MIXIN : private WinsockInitializer
00030 #else
00031 # define SOCKET_INITIALIZER_MIXIN
00032 #endif
00033 
00034 #if defined __CYGWIN__ || defined __WIN32__
00035 # include "safewindows.h" // Only for HANDLE!
00036 #endif
00037 
00042 class XAPIAN_VISIBILITY_DEFAULT TcpServer SOCKET_INITIALIZER_MIXIN {
00044     void operator=(const TcpServer &);
00045 
00047     TcpServer(const TcpServer &);
00048 
00053     const std::vector<std::string> dbpaths;
00054 
00056     bool writable;
00057 
00058 #if defined __CYGWIN__ || defined __WIN32__
00060     HANDLE mutex;
00061 #endif
00062 
00064     int listen_socket;
00065 
00067     int msecs_active_timeout;
00068 
00070     int msecs_idle_timeout;
00071 
00073     bool verbose;
00074 
00081     static int get_listening_socket(const std::string & host, int port
00082 #if defined __CYGWIN__ || defined __WIN32__
00083                                     , HANDLE &mutex
00084 #endif
00085             );
00086 
00088     int accept_connection();
00089 
00090   public:
00106     TcpServer(const std::vector<std::string> &dbpaths_,
00107               const std::string &host, int port,
00108               int msecs_active_timeout,
00109               int msecs_idle_timeout,
00110               bool writable,
00111               bool verbose);
00112 
00114     ~TcpServer();
00115 
00122     void run();
00123 
00125     void run_once();
00126 
00132     void handle_one_connection(int socket);
00133 };
00134 
00135 #endif  // XAPIAN_INCLUDED_TCPSERVER_H

Documentation for Xapian (version 1.0.10).
Generated on 24 Dec 2008 by Doxygen 1.5.2.