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

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