#ifndef _SERVER_CORE_SERVER_MODULE_ #define _SERVER_CORE_SERVER_MODULE_ #include #include #ifndef __linux__ // #include #define WIN32_LEAN_AND_MEAN #include #include #include #else #include #include #include /* low-level i/o */ #include #include #include #include #include #include #include #include #include #include #include #include #include #endif #include "../../components/base/basicLogCollection.h" #include "../../components/base/basicSettingsProvider.h" #include "../../components/base/basicThread.h" #include "../../components/base/basicTypes.h" #include #include #include #include // #include "../../components/base/basicEngine.h" #include "../../components/base/basicEventHeap.h" #include "../protocol/protocol.h" #include "netClientHandler.h" #include "netServiceEngine.h" #ifndef _SERVER_APPLICATION_ #define AUTOMATIC_IP_DETECTION #endif // #define USE_SSL_ENCRIPTION #ifdef USE_SSL_ENCRIPTION #include "../../components/obect/objectCertStorage.h" #endif #define NWS_SETTINGS_HOST "NW_HOSTNAME_IP" #define NWS_SETTINGS_PORT "NW_LISTEN_PORT" // typedef _Primitive_Ring<_Core_Channel> ChannelsRing; typedef std::vector vectorNetHandlers; // TCP keepalive on accepted connections: a dead peer is detected after IDLE + INTERVAL * PROBES seconds #define NWS_KEEPALIVE_IDLE_S 30 #define NWS_KEEPALIVE_INTERVAL_S 10 #define NWS_KEEPALIVE_PROBES 3 #define INVALID_SOCKET -1 #define UNIX_PATH_MAX 108 void signal_void_handler(int SIG); class networkServer : public basicThread, public basicEventHandler { private: vectorNetHandlers m_vHandlersPool; networkServiceEngine * m_pKernelEngine; config_setting_t * m_pSettings; protected: basicLogCollection * m_pLog; struct sockaddr * MainSocketAddress; CSTR m_pHostName; uint16_t m_nPortNumber; #ifdef __linux__ int MainSocket; #else SOCKET MainSocket; #endif U8 m_bConnectionType; void m_fThreadProc(void); void cleanupClients(void); public: explicit networkServer(config_setting_t * Settings = NULL, networkServiceEngine * ptr = NULL); virtual ~networkServer(); bool BootUp(void); // Config By Settings provided in constructor, on fail uses next BootUp #ifdef USE_SSL_ENCRIPTION bool BootUp(U16 Port, bool useSSL = false); // Uses Default Hostname and Port as parameter, on fail (getlocalhost) uses next Bootup bool BootUp(CSTR HOST_NAME, U16 Port, bool useSSL = false); // Uses parameters #else bool BootUp(U16 Port); // Uses Default Hostname and Port as parameter, on fail (getlocalhost) uses next Bootup bool BootUp(CSTR HOST_NAME, U16 Port); // Uses parameters #endif #ifdef __linux__ bool BootUp(CSTR UNIX_SOCKET_NAME); #endif bool attachEngine(networkServiceEngine * ptr); virtual bool dispatchEvent(EVENT_CONTAINER * Evt); CSTR getAddress(void) { /* if( m_pHostName ) return strdup( m_pHostName ); */ return NULL; } CSTR getHostname(void) { if (m_pHostName) { return strdup(m_pHostName); } } uint16_t getPort(void) { return m_nPortNumber; } }; #endif