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.

116 lines
3.6 KiB

7 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
7 years ago
​
​
​
​
​
​
​
​
​
​
​
7 years ago
​
7 years ago
​
2 years ago
​
​
​
​
​
​
​
​
7 years ago
​
​
​
​
​
2 years ago
​
7 years ago
​
​
​
​
2 years ago
2 years ago
​
​
​
7 years ago
7 years ago
7 years ago
​
7 years ago
​
​
​
​
​
7 years ago
7 years ago
5 years ago
​
7 years ago
​
​
  1. #ifndef _SERVER_CORE_SERVER_MODULE_
  2. #define _SERVER_CORE_SERVER_MODULE_
  3. #include <stdio.h>
  4. #include <signal.h>
  5. #ifndef __linux__
  6. // #include <WinSock2.h>
  7. #define WIN32_LEAN_AND_MEAN
  8. #include <windows.h>
  9. #include <winsock2.h>
  10. #include <ws2tcpip.h>
  11. #else
  12. #include <sys/socket.h>
  13. #include <netinet/in.h>
  14. #include <netinet/ip.h>
  15. #include <netdb.h>
  16. #include <sys/un.h>
  17. #include <sys/types.h>
  18. #include <fcntl.h>
  19. #include <sys/ioctl.h>
  20. #include <unistd.h>
  21. #include <errno.h>
  22. #include <fcntl.h> /* low-level i/o */
  23. #include <unistd.h>
  24. #include <errno.h>
  25. #include <sys/stat.h>
  26. #include <sys/types.h>
  27. #include <sys/time.h>
  28. #include <sys/mman.h>
  29. #include <sys/ioctl.h>
  30. #include <linux/types.h>
  31. #endif
  32. #include <stdlib.h>
  33. #include <stdio.h>
  34. #include <string.h>
  35. #include <vector>
  36. #include "../../components/base/basicTypes.h"
  37. #include "../../components/base/basicThread.h"
  38. #include "../../components/base/basicLogCollection.h"
  39. #include "../../components/base/basicLogCollection.h"
  40. #include "../../components/base/basicSettingsProvider.h"
  41. //#include "../../components/base/basicEngine.h"
  42. #include "../../components/base/basicEventHeap.h"
  43. #include "../protocol/protocol.h"
  44. #include "netServiceEngine.h"
  45. #include "netClientHandler.h"
  46. #ifndef _SERVER_APPLICATION_
  47. #define AUTOMATIC_IP_DETECTION
  48. #endif
  49. //#define USE_SSL_ENCRIPTION
  50. #ifdef USE_SSL_ENCRIPTION
  51. #include "../../components/obect/objectCertStorage.h"
  52. #endif
  53. #define NWS_SETTINGS_HOST "NW_HOSTNAME_IP"
  54. #define NWS_SETTINGS_PORT "NW_LISTEN_PORT"
  55. //typedef _Primitive_Ring<_Core_Channel> ChannelsRing;
  56. typedef std::vector<networkClientHandler *> vectorNetHandlers;
  57. #define INVALID_SOCKET -1
  58. #define UNIX_PATH_MAX 108
  59. void signal_void_handler( int SIG );
  60. class networkServer: public basicThread, public basicEventHandler{
  61. private:
  62. vectorNetHandlers m_vHandlersPool;
  63. networkServiceEngine * m_pKernelEngine;
  64. config_setting_t * m_pSettings;
  65. protected:
  66. basicLogCollection * m_pLog;
  67. struct sockaddr * MainSocketAddress;
  68. CSTR m_pHostName;
  69. uint16_t m_nPortNumber;
  70. #ifdef __linux__
  71. int MainSocket;
  72. #else
  73. SOCKET MainSocket;
  74. #endif
  75. U8 m_bConnectionType;
  76. void m_fThreadProc( void );
  77. public:
  78. explicit networkServer( config_setting_t *Settings = NULL, networkServiceEngine *ptr=NULL );
  79. virtual ~networkServer();
  80. bool BootUp( void ); // Config By Settings provided in constructor, on fail uses next BootUp
  81. #ifdef USE_SSL_ENCRIPTION
  82. bool BootUp( U16 Port, bool useSSL = false ); // Uses Default Hostname and Port as parameter, on fail (getlocalhost) uses next Bootup
  83. bool BootUp( CSTR HOST_NAME, U16 Port, bool useSSL = false ); // Uses parameters
  84. #else
  85. bool BootUp( U16 Port ); // Uses Default Hostname and Port as parameter, on fail (getlocalhost) uses next Bootup
  86. bool BootUp( CSTR HOST_NAME, U16 Port ); // Uses parameters
  87. #endif
  88. #ifdef __linux__
  89. bool BootUp( CSTR UNIX_SOCKET_NAME );
  90. #endif
  91. bool attachEngine( networkServiceEngine *ptr );
  92. virtual bool dispatchEvent( EVENT_CONTAINER *Evt );
  93. CSTR getAddress( void ){ /* if( m_pHostName ) return strdup( m_pHostName ); */ return NULL; };
  94. CSTR getHostname( void ){ if( m_pHostName ) return strdup( m_pHostName ); };
  95. uint16_t getPort( void ){ return m_nPortNumber; };
  96. };
  97. #endif