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.

96 lines
2.9 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
​
​
  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 "netClientHandler.h"
  45. #define AUTOMATIC_IP_DETECTION
  46. #define NWS_SETTINGS_HOST "NW_HOSTNAME_IP"
  47. #define NWS_SETTINGS_PORT "NW_LISTEN_PORT"
  48. //typedef _Primitive_Ring<_Core_Channel> ChannelsRing;
  49. typedef std::vector<networkClientHandler *> vectorNetHandlers;
  50. #define UNIX_PATH_MAX 108
  51. void signal_void_handler( int SIG );
  52. class networkServer: public basicThread, public basicEventHandler{
  53. private:
  54. basicLogCollection * m_pLog;
  55. vectorNetHandlers m_vHandlersPool;
  56. basicEngine * m_pKernelEngine;
  57. config_setting_t * m_pSettings;
  58. struct sockaddr * MainSocketAddress;
  59. CSTR m_pHostName;
  60. uint16_t m_nPortNumber;
  61. #ifdef __linux__
  62. int MainSocket;
  63. #else
  64. SOCKET MainSocket;
  65. #endif
  66. U8 m_bConnectionType;
  67. protected:
  68. void m_fThreadProc( void );
  69. public:
  70. explicit networkServer( config_setting_t *Settings = NULL, basicEngine *ptr=NULL );
  71. virtual ~networkServer();
  72. bool BootUp( void ); // Config By Settings provided in constructor, on fail uses next BootUp
  73. bool BootUp( U16 Port ); // Uses Default Hostname and Port as parameter, on fail (getlocalhost) uses next Bootup
  74. bool BootUp( CSTR HOST_NAME, U16 Port ); // Uses parameters
  75. #ifdef __linux__
  76. bool BootUp( CSTR UNIX_SOCKET_NAME );
  77. #endif
  78. bool attachEngine( basicEngine *ptr );
  79. void dispatchEvent( basicEvent *Evt );
  80. CSTR getAddress( void ){ return m_pHostName; };
  81. uint16_t getPort( void ){ return m_nPortNumber; };
  82. };
  83. #endif