You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

127 lines
3.1 KiB

#ifndef _SERVER_CORE_SERVER_MODULE_
#define _SERVER_CORE_SERVER_MODULE_
#include <signal.h>
#include <stdio.h>
#ifndef __linux__
// #include <WinSock2.h>
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <winsock2.h>
#include <ws2tcpip.h>
#else
#include <errno.h>
#include <fcntl.h>
#include <fcntl.h> /* low-level i/o */
#include <linux/types.h>
#include <netdb.h>
#include <netinet/in.h>
#include <netinet/ip.h>
#include <sys/ioctl.h>
#include <sys/mman.h>
#include <sys/socket.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <sys/types.h>
#include <sys/un.h>
#include <unistd.h>
#endif
#include "../../components/base/basicLogCollection.h"
#include "../../components/base/basicSettingsProvider.h"
#include "../../components/base/basicThread.h"
#include "../../components/base/basicTypes.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <vector>
// #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<networkClientHandler *> vectorNetHandlers;
#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);
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