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.

83 lines
2.3 KiB

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. #endif
  23. #include <stdlib.h>
  24. #include <stdio.h>
  25. #include <string.h>
  26. #include <vector>
  27. #include "../../components/base/basicTypes.h"
  28. #include "../../components/base/basicThread.h"
  29. #include "../../components/base/basicLogCollection.h"
  30. #include "../../components/base/basicLogCollection.h"
  31. #include "../../components/base/basicSettingsProvider.h"
  32. #include "../../components/base/basicEngine.h"
  33. #include "../../components/base/basicEventHeap.h"
  34. #include "../protocol/protocol.h"
  35. #include "netClientHandler.h"
  36. #define NWS_SETTINGS_HOST "NW_HOSTNAME_IP"
  37. #define NWS_SETTINGS_PORT "NW_LISTEN_PORT"
  38. //typedef _Primitive_Ring<_Core_Channel> ChannelsRing;
  39. typedef std::vector<networkClientHandler *> vectorNetHandlers;
  40. #define UNIX_PATH_MAX 108
  41. void signal_void_handler( int SIG );
  42. class networkServer: public basicThread, public basicEventHandler{
  43. private:
  44. basicLogCollection *m_pLog;
  45. vectorNetHandlers m_vHandlersPool;
  46. basicEngine *m_pDetectorKernel;
  47. config_setting_t *m_pSettings;
  48. struct sockaddr *MainSocketAddress;
  49. CSTR m_pHostName;
  50. uint16_t m_nPortNumber;
  51. #ifdef __linux__
  52. int MainSocket;
  53. #else
  54. SOCKET MainSocket;
  55. #endif
  56. U8 m_bConnectionType;
  57. protected:
  58. void m_fThreadProc( void );
  59. public:
  60. explicit networkServer( config_setting_t *Settings = NULL );
  61. virtual ~networkServer();
  62. bool BootUp( void ); // Config By Settings provided in constructor, on fail uses next BootUp
  63. bool BootUp( U16 Port ); // Uses Default Hostname and Port as parameter, on fail (getlocalhost) uses next Bootup
  64. bool BootUp( CSTR HOST_NAME, U16 Port ); // Uses parameters
  65. #ifdef __linux__
  66. bool BootUp( CSTR UNIX_SOCKET_NAME );
  67. #endif
  68. bool attachEngine( basicEngine *ptr );
  69. void dispatchEvent( basicEvent *Evt );
  70. };
  71. #endif