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.

108 lines
3.2 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 USE_SSL_ENCRIPTION
  48. #ifdef USE_SSL_ENCRIPTION
  49. #include "../../components/obect/objectCertStorage.h"
  50. #endif
  51. #define NWS_SETTINGS_HOST "NW_HOSTNAME_IP"
  52. #define NWS_SETTINGS_PORT "NW_LISTEN_PORT"
  53. //typedef _Primitive_Ring<_Core_Channel> ChannelsRing;
  54. typedef std::vector<networkClientHandler *> vectorNetHandlers;
  55. #define UNIX_PATH_MAX 108
  56. void signal_void_handler( int SIG );
  57. class networkServer: public basicThread, public basicEventHandler{
  58. private:
  59. basicLogCollection * m_pLog;
  60. vectorNetHandlers m_vHandlersPool;
  61. networkServiceEngine * m_pKernelEngine;
  62. config_setting_t * m_pSettings;
  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. protected:
  73. void m_fThreadProc( void );
  74. public:
  75. explicit networkServer( config_setting_t *Settings = NULL, networkServiceEngine *ptr=NULL );
  76. virtual ~networkServer();
  77. bool BootUp( void ); // Config By Settings provided in constructor, on fail uses next BootUp
  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. #ifdef __linux__
  81. bool BootUp( CSTR UNIX_SOCKET_NAME );
  82. #endif
  83. bool attachEngine( networkServiceEngine *ptr );
  84. void dispatchEvent( EVENT_CONTAINER *Evt );
  85. CSTR getAddress( void ){ /* if( m_pHostName ) return strdup( m_pHostName ); */ return NULL; };
  86. CSTR getHostname( void ){ if( m_pHostName ) return strdup( m_pHostName ); };
  87. uint16_t getPort( void ){ return m_nPortNumber; };
  88. };
  89. #endif