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.

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