Sleipnir
src/serveri.h
00001 /*****************************************************************************
00002 * This file is provided under the Creative Commons Attribution 3.0 license.
00003 *
00004 * You are free to share, copy, distribute, transmit, or adapt this work
00005 * PROVIDED THAT you attribute the work to the authors listed below.
00006 * For more information, please see the following web page:
00007 * http://creativecommons.org/licenses/by/3.0/
00008 *
00009 * This file is a component of the Sleipnir library for functional genomics,
00010 * authored by:
00011 * Curtis Huttenhower (chuttenh@princeton.edu)
00012 * Mark Schroeder
00013 * Maria D. Chikina
00014 * Olga G. Troyanskaya (ogt@princeton.edu, primary contact)
00015 *
00016 * If you use this library, the included executable tools, or any related
00017 * code in your work, please cite the following publication:
00018 * Curtis Huttenhower, Mark Schroeder, Maria D. Chikina, and
00019 * Olga G. Troyanskaya.
00020 * "The Sleipnir library for computational functional genomics"
00021 *****************************************************************************/
00022 #ifndef SERVERI_H
00023 #define SERVERI_H
00024 
00025 namespace Sleipnir {
00026 
00027 class CServer;
00028 class IServerClient;
00029 
00030 class CServerImpl {
00031 protected:
00032     typedef std::map<IServerClient*, pthread_t> TMapThreads;
00033     typedef std::vector<IServerClient*>         TVecClients;
00034 
00035     static const char*  c_szPort;
00036     static const char*  c_szTimeout;
00037     static CServer*     s_pServer;
00038 
00039 #ifndef _MSC_VER
00040     static void Alarm( int );
00041 #endif // _MSC_VER
00042 
00043     void Listen( );
00044 
00045     int             m_iPort;
00046     int             m_iTimeout;
00047     SOCKET          m_iSocket;
00048     bool            m_fStop;
00049     IServerClient*  m_pClient;
00050 };
00051 
00052 class CServerClientImpl {
00053 public:
00054     static void* StartRoutine( void* );
00055 
00056     CServerClientImpl( SOCKET, IServerClient* );
00057 
00058 private:
00059     static const size_t c_iBuffer   = 131072;
00060 
00061     ~CServerClientImpl( );
00062 
00063     void StartRoutine( );
00064     void ReadMessage( );
00065 
00066     SOCKET                      m_iSocket;
00067     IServerClient*              m_pClient;
00068     std::vector<unsigned char>  m_vecbMessage;
00069 };
00070 
00071 }
00072 
00073 #endif // SERVERI_H