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.

605 lines
16 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
​
​
​
​
​
​
​
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
​
3 years ago
​
​
​
​
3 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
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
​
​
​
​
​
​
​
​
​
​
​
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
​
​
​
​
​
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
​
​
​
​
​
​
7 years ago
1 year ago
7 years ago
2 years ago
​
​
​
1 year ago
1 year ago
​
​
​
​
​
​
​
​
​
​
7 years ago
12 months 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
2 years ago
​
2 years ago
2 years ago
​
​
​
​
2 years ago
2 years ago
​
​
​
​
​
2 years ago
2 years ago
​
​
7 years ago
​
2 years ago
2 years ago
7 years ago
​
​
​
​
​
​
​
7 years ago
​
​
  1. #include "netServer.h"
  2. // #include "../../App/3dSERVER/LRF_ClientHandler.h"
  3. #include "netClientHandler.h"
  4. #define LOG(X) m_pLog->Log("NS", this, X)
  5. #ifdef DEBUG
  6. #define LOG_ERROR(X) \
  7. { \
  8. char _tBfrErrMSG234[256]; \
  9. sprintf(_tBfrErrMSG234, "In file %s[%d] in func:%s %s", __FILE__, __LINE__, __func__, X); \
  10. m_pLog->Log("NS", this, _LOG_ERROR, _tBfrErrMSG234); \
  11. }
  12. #else
  13. #define LOG_ERROR(X) m_pLog->Log("NS", this, _LOG_ERROR, X);
  14. #endif
  15. void signal_void_handler(int SIG) {
  16. if ( SIG ) SIG = 121; // dummy to prevent Warnings
  17. }
  18. networkServer::networkServer(config_setting_t * Settings, networkServiceEngine * ptr) :
  19. basicThread()
  20. {
  21. m_pLog = basicLogCollection::getInstance();
  22. m_bConnectionType = 0;
  23. m_vHandlersPool.clear();
  24. MainSocketAddress = NULL;
  25. m_pKernelEngine = ptr;
  26. MainSocket = INVALID_SOCKET;
  27. if (Settings != NULL)
  28. {
  29. m_pSettings = Settings;
  30. }
  31. else
  32. {
  33. m_pSettings = basicSettingsProvider::getInstance()->getSubNode(NULL, "NETWORK_SERVER");
  34. };
  35. }
  36. networkServer::~networkServer()
  37. {
  38. m_bThreadStatus = TH_ENDED;
  39. if (m_pHostName != NULL)
  40. {
  41. free(m_pHostName);
  42. }
  43. }
  44. bool networkServer::BootUp(void)
  45. {
  46. config_setting_t * pSetting;
  47. int tVal;
  48. char tBuffer[CTEXT];
  49. m_pHostName = NULL;
  50. if (m_pSettings != NULL)
  51. {
  52. LOG("NetServer Getting Settings ...");
  53. #ifdef AUTOMATIC_IP_DETECTION
  54. struct ifaddrs * ifaddr = NULL;
  55. struct ifaddrs * ifa;
  56. m_pHostName = (CSTR) malloc(CTEXT);
  57. if (-1 == getifaddrs(&ifaddr))
  58. {
  59. LOG_ERROR("Cannot get Net Integfaces!");
  60. return false;
  61. }
  62. else
  63. {
  64. bool regs = false;
  65. char ip[16];
  66. struct sockaddr_in * inn;
  67. unsigned char A, B, C, D;
  68. #ifdef DEBUG
  69. LOG("Gotta check some IFs");
  70. #endif
  71. for (ifa = ifaddr; ifa; ifa = ifa->ifa_next)
  72. {
  73. if (ifa->ifa_addr == NULL)
  74. {
  75. // Can Bus
  76. LOG("IFA->ifa_addr is NULL");
  77. continue;
  78. };
  79. if (ifa->ifa_addr->sa_family != AF_INET)
  80. {
  81. continue;
  82. }
  83. inn = (struct sockaddr_in *) ifa->ifa_addr;
  84. D = (inn->sin_addr.s_addr >> 24) & 0xFF;
  85. C = (inn->sin_addr.s_addr >> 16) & 0xFF;
  86. B = (inn->sin_addr.s_addr >> 8) & 0xFF;
  87. A = (inn->sin_addr.s_addr >> 0) & 0xFF;
  88. sprintf(ip, "%d.%d.%d.%d", A, B, C, D);
  89. sprintf(tBuffer, "Network Interface: %s [%s]", ifa->ifa_name, ip);
  90. if (strncmp(ifa->ifa_name, "eth", 3) == 0 || strncmp(ifa->ifa_name, "enp", 3) == 0)
  91. {
  92. regs = true;
  93. sprintf(m_pHostName, ip);
  94. };
  95. LOG(tBuffer);
  96. };
  97. if (! regs)
  98. {
  99. free(m_pHostName);
  100. m_pHostName = NULL;
  101. LOG_ERROR("Ethernet IP address Not Detected! Using Settings");
  102. if (! config_setting_lookup_string(m_pSettings, NWS_SETTINGS_HOST, (const char **) &m_pHostName))
  103. {
  104. m_pHostName = (CSTR) malloc(CTEXT);
  105. sprintf(m_pHostName, "localhost");
  106. pSetting = config_setting_add(m_pSettings, NWS_SETTINGS_HOST, CONFIG_TYPE_STRING);
  107. config_setting_set_string(pSetting, m_pHostName);
  108. basicSettingsProvider::getInstance()->compromise();
  109. LOG("No Host defined");
  110. }
  111. else
  112. {
  113. sprintf(tBuffer, "Host Address Read From Settings: %s", m_pHostName);
  114. LOG(tBuffer);
  115. };
  116. };
  117. freeifaddrs(ifaddr);
  118. };
  119. #else
  120. if (! config_setting_lookup_string(m_pSettings, NWS_SETTINGS_HOST, (const char **) &m_pHostName))
  121. {
  122. m_pHostName = (CSTR) malloc(CTEXT);
  123. sprintf(m_pHostName, "localhost");
  124. pSetting = config_setting_add(m_pSettings, NWS_SETTINGS_HOST, CONFIG_TYPE_STRING);
  125. config_setting_set_string(pSetting, m_pHostName);
  126. basicSettingsProvider::getInstance()->compromise();
  127. LOG("No Host defined");
  128. }
  129. else
  130. {
  131. sprintf(tBuffer, "Host Address Read From Settings: %s", m_pHostName);
  132. LOG(tBuffer);
  133. };
  134. #endif
  135. if (! config_setting_lookup_int(m_pSettings, NWS_SETTINGS_PORT, &tVal))
  136. {
  137. m_nPortNumber = 2222;
  138. pSetting = config_setting_add(m_pSettings, NWS_SETTINGS_PORT, CONFIG_TYPE_INT);
  139. config_setting_set_int(pSetting, m_nPortNumber);
  140. basicSettingsProvider::getInstance()->compromise();
  141. LOG("No Port defined");
  142. }
  143. else
  144. {
  145. m_nPortNumber = tVal;
  146. sprintf(tBuffer, "Port Read From Settings: %d", m_nPortNumber);
  147. LOG(tBuffer);
  148. };
  149. sprintf(tBuffer, "Final Network Config is: %s:%d", m_pHostName, m_nPortNumber);
  150. LOG(tBuffer);
  151. if (basicSettingsProvider::getInstance()->isCompromised())
  152. {
  153. basicSettingsProvider::getInstance()->validate();
  154. }
  155. return BootUp(m_pHostName, m_nPortNumber);
  156. }
  157. else
  158. {
  159. // Last try to bootup by detecting host and default port 2222
  160. return BootUp(2222);
  161. };
  162. }
  163. bool networkServer::BootUp(CSTR HOST_NAME, U16 PORT)
  164. {
  165. #ifdef __linux__
  166. int RetCode;
  167. struct hostent * h_info;
  168. #ifdef DEBUG
  169. LOG("BootUp");
  170. #endif
  171. MainSocket = socket(AF_INET, SOCK_STREAM, 0);
  172. if (MainSocket == -1)
  173. {
  174. LOG_ERROR("Some throuble with networking on this machine (Socket Error)!");
  175. return false;
  176. };
  177. const int enable = 1;
  178. if (setsockopt(MainSocket, SOL_SOCKET, SO_REUSEADDR, &enable, sizeof(int)) < 0)
  179. {
  180. LOG_ERROR("setsockopt(SO_REUSEADDR) failed");
  181. };
  182. MainSocketAddress = NULL;
  183. MainSocketAddress = (struct sockaddr *) malloc(sizeof(struct sockaddr_in));
  184. if (MainSocketAddress == NULL)
  185. {
  186. LOG_ERROR("Some throuble with networking on this machine (Cannot Alloc Sockaddr Struct)!");
  187. return false;
  188. };
  189. bzero(MainSocketAddress, sizeof(struct sockaddr_in));
  190. h_info = gethostbyname(HOST_NAME);
  191. if (h_info == NULL)
  192. {
  193. LOG_ERROR("Some throuble with networking on this machine (Cannot Get Hostname)!");
  194. return false;
  195. };
  196. //*****************************************
  197. //* there we building our network address *
  198. //*****************************************
  199. bcopy(h_info->h_addr, &(((struct sockaddr_in *) MainSocketAddress)->sin_addr), h_info->h_length);
  200. ((struct sockaddr_in *) MainSocketAddress)->sin_family = h_info->h_addrtype;
  201. ((struct sockaddr_in *) MainSocketAddress)->sin_port = htons(PORT);
  202. RetCode = bind(MainSocket, MainSocketAddress, sizeof(struct sockaddr_in));
  203. if (RetCode != 0)
  204. {
  205. LOG_ERROR("Error Binding to Port/Address");
  206. return false;
  207. };
  208. RetCode = listen(MainSocket, 128);
  209. if (RetCode != 0)
  210. {
  211. LOG_ERROR("Cannot Listen Port/Address");
  212. return false;
  213. };
  214. int flags;
  215. flags = fcntl(MainSocket, F_GETFL, NULL);
  216. flags |= O_NONBLOCK | O_NDELAY;
  217. // RetCode = ioctl( MainSocket, FIONBIO, (char *) &dontblock );
  218. RetCode = fcntl(MainSocket, F_SETFL, flags);
  219. if (RetCode == 0)
  220. {
  221. LOG("Set N-Blocking Mode of Accepting Socket");
  222. }
  223. else
  224. {
  225. LOG("Can't set N-Blocking Mode of Accepting Socket");
  226. };
  227. #else
  228. char temp[CTEXT];
  229. WSADATA wsaData;
  230. int iResult;
  231. // Initialize Winsock
  232. iResult = WSAStartup(MAKEWORD(2, 2), &wsaData);
  233. if (iResult != 0)
  234. {
  235. sprintf(temp, "WSAStartup failed with error: %d\n", iResult);
  236. LOG_ERROR(temp);
  237. return false;
  238. };
  239. MainSocket = INVALID_SOCKET;
  240. SOCKET ClientSocket = INVALID_SOCKET;
  241. struct addrinfo * result = NULL;
  242. struct addrinfo hints;
  243. int iSendResult;
  244. char recvbuf[512];
  245. int recvbuflen = 512;
  246. ZeroMemory(&hints, sizeof(hints));
  247. hints.ai_family = AF_INET;
  248. hints.ai_socktype = SOCK_STREAM;
  249. hints.ai_protocol = IPPROTO_TCP;
  250. hints.ai_flags = AI_PASSIVE;
  251. // Resolve the server address and port
  252. sprintf(temp, "%d", PORT);
  253. iResult = getaddrinfo(NULL, temp, &hints, &result);
  254. if (iResult != 0)
  255. {
  256. sprintf(temp, "getaddrinfo failed with error: %d\n", iResult);
  257. LOG_ERROR(temp);
  258. WSACleanup();
  259. return false;
  260. };
  261. // Create a SOCKET for connecting to server
  262. MainSocket = socket(result->ai_family, result->ai_socktype, result->ai_protocol);
  263. if (MainSocket == INVALID_SOCKET)
  264. {
  265. sprintf(temp, "socket failed with error: %ld\n", WSAGetLastError());
  266. LOG_ERROR(temp);
  267. freeaddrinfo(result);
  268. WSACleanup();
  269. return false;
  270. };
  271. // Setup the TCP listening socket
  272. iResult = bind(MainSocket, result->ai_addr, (int) result->ai_addrlen);
  273. if (iResult == SOCKET_ERROR)
  274. {
  275. sprintf(temp, "bind failed with error: %d\n", WSAGetLastError());
  276. LOG_ERROR(temp);
  277. freeaddrinfo(result);
  278. closesocket(MainSocket);
  279. WSACleanup();
  280. return false;
  281. };
  282. freeaddrinfo(result);
  283. iResult = listen(MainSocket, SOMAXCONN);
  284. if (iResult == SOCKET_ERROR)
  285. {
  286. sprintf(temp, "listen failed with error: %d\n", WSAGetLastError());
  287. LOG_ERROR(temp);
  288. closesocket(MainSocket);
  289. WSACleanup();
  290. return false;
  291. };
  292. #endif
  293. m_bConnectionType = 1;
  294. return init();
  295. }
  296. bool networkServer::BootUp(U16 Port)
  297. {
  298. char temp[CTEXT];
  299. m_nPortNumber = Port;
  300. #ifdef __linux__
  301. int RetCode;
  302. size_t S_NAMLEN = CTEXT;
  303. RetCode = gethostname(m_pHostName, S_NAMLEN);
  304. if ( RetCode < 0 ) {
  305. LOG_ERROR("Can't Get Hostname!");
  306. };
  307. sprintf(temp, "Running on host: %s:%d", m_pHostName, m_nPortNumber);
  308. LOG(temp);
  309. #else
  310. sprintf(m_pHostName, "");
  311. #endif
  312. return BootUp(m_pHostName, m_nPortNumber);
  313. }
  314. bool networkServer::attachEngine(networkServiceEngine * ptr)
  315. {
  316. m_pKernelEngine = ptr;
  317. if (m_vHandlersPool.size())
  318. {
  319. // Pass Kernel to all already connected nodes
  320. for (vectorNetHandlers::iterator index = m_vHandlersPool.begin(); index < m_vHandlersPool.end(); index++)
  321. {
  322. //((LRF_ClientHandler *)(*index))->attachEngine(m_pDetectorKernel);
  323. (*index)->attachEngine(m_pKernelEngine);
  324. };
  325. };
  326. return true;
  327. }
  328. #ifdef __linux__
  329. bool networkServer::BootUp(CSTR SOCKET_NAME)
  330. {
  331. //struct sockaddr_un MainPort;
  332. //size_t S_NAMLEN = CTEXT;
  333. int RetCode;
  334. char localhost[CTEXT];
  335. char temp[512];
  336. LOG("Core BootUp");
  337. MainSocket = socket(PF_UNIX, SOCK_STREAM, 0);
  338. if (MainSocket == -1)
  339. {
  340. LOG_ERROR("Some throuble with Kernel on this machine (UnixSocket Error)!");
  341. return false;
  342. };
  343. if (unlink(SOCKET_NAME) == -1)
  344. {
  345. LOG("Old Socket File was not deleted!");
  346. };
  347. localhost[0] = 0;
  348. // RetCode = gethostname( localhost, S_NAMLEN );
  349. sprintf(temp, "Running Unix Socket: %s::%s", localhost, SOCKET_NAME);
  350. LOG(temp);
  351. MainSocketAddress = (sockaddr *) malloc(sizeof(struct sockaddr_un));
  352. bzero(MainSocketAddress, sizeof(struct sockaddr_un));
  353. //*****************************************
  354. //* there we building our network address *
  355. //*****************************************
  356. ((struct sockaddr_un *) MainSocketAddress)->sun_family = AF_UNIX;
  357. snprintf(((struct sockaddr_un *) MainSocketAddress)->sun_path, UNIX_PATH_MAX, SOCKET_NAME);
  358. RetCode = bind(MainSocket, MainSocketAddress, sizeof(struct sockaddr_un));
  359. if (RetCode != 0)
  360. {
  361. LOG_ERROR("Error Binding to Port/Address");
  362. return false;
  363. };
  364. RetCode = listen(MainSocket, 128);
  365. if (RetCode != 0)
  366. {
  367. LOG_ERROR("Cannot Listen UNIX SOCKET");
  368. return false;
  369. };
  370. U8 dontblock;
  371. // Set Socket permitions 666
  372. fchmod(MainSocket, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH);
  373. dontblock = fcntl(MainSocket, F_GETFL, NULL);
  374. dontblock |= O_NONBLOCK | O_NDELAY;
  375. RetCode = ioctl(MainSocket, FIONBIO, (char *) &dontblock);
  376. if (RetCode == 0)
  377. {
  378. LOG("Set N-Blocking Mode of Master Socket");
  379. }
  380. else
  381. {
  382. LOG("Can't set N-Blocking Mode of Master Socket");
  383. };
  384. m_bConnectionType = 2;
  385. return init();
  386. }
  387. #endif
  388. void networkServer::m_fThreadProc(void)
  389. {
  390. struct sockaddr ClientAddress;
  391. socklen_t size;
  392. int RetCode;
  393. #ifdef __linux__
  394. int ClientSocket;
  395. if (m_bConnectionType == 1)
  396. {
  397. size = (socklen_t) sizeof(struct sockaddr_in);
  398. }
  399. else
  400. {
  401. size = (socklen_t) sizeof(struct sockaddr_un);
  402. };
  403. #else
  404. SOCKET ClientSocket;
  405. #endif
  406. #ifdef DEBUG
  407. LOG("Core Worker Thread Started");
  408. LOG("Ready to Accept Connections");
  409. #endif
  410. pthread_setname_np(pthread_self(), "networkServer");
  411. m_bThreadStatus = TH_WORKING;
  412. while (m_bThreadStatus < TH_ENDED)
  413. {
  414. ClientSocket = accept(MainSocket, &ClientAddress, &size);
  415. if (ClientSocket < 0)
  416. {
  417. switch (errno)
  418. {
  419. case EAGAIN:
  420. {
  421. // Checkup client disconnection
  422. if (m_vHandlersPool.size())
  423. {
  424. for (vectorNetHandlers::iterator index = m_vHandlersPool.begin(); index < m_vHandlersPool.end();)
  425. {
  426. // LRF_ClientHandler *tClient = (LRF_ClientHandler *)(*index);
  427. if ((*index)->getStatus() == false)
  428. {
  429. // Remove Client Handler
  430. #ifdef DEBUG_EXTRA
  431. LOG("Remove Client");
  432. #endif
  433. if (m_pKernelEngine)
  434. {
  435. if (m_pKernelEngine->detachClient(*index))
  436. {
  437. #ifdef DEBUG_EXTRA
  438. LOG("Client Stoped");
  439. #endif
  440. m_vHandlersPool.erase(index);
  441. #ifdef DEBUG_EXTRA
  442. LOG("Remove Client Done");
  443. #endif
  444. continue;
  445. }
  446. else
  447. {
  448. LOG_ERROR("Client detach from Kernel Failure!");
  449. }
  450. }
  451. else
  452. {
  453. LOG_ERROR("No Kernel Attached!");
  454. }
  455. };
  456. index++;
  457. };
  458. };
  459. SLEEP(10);
  460. continue;
  461. };
  462. // case EWOULDBLOCK: me->Log(" The socket is marked non-blocking and no connections are present to be accepted."); break;
  463. case EBADF : LOG_ERROR("The descriptor is invalid."); break;
  464. case ECONNABORTED: LOG_ERROR("A connection has been aborted."); break;
  465. case EINTR : LOG_ERROR("The system call was interrupted by a signal that was caught before a valid connection arrived."); break;
  466. case EINVAL : LOG_ERROR("Socket is not listening for connections, or addrlen is invalid (e.g., is negative)."); break;
  467. case EMFILE : LOG_ERROR("The per-process limit of open file descriptors has been reached."); break;
  468. case ENFILE : LOG_ERROR("The system limit on the total number of open files has been reached."); break;
  469. case ENOTSOCK : LOG_ERROR("The descriptor references a file, not a socket."); break;
  470. case EOPNOTSUPP : LOG_ERROR("The referenced socket is not of type SOCK_STREAM."); break;
  471. case EFAULT : LOG_ERROR("The addr argument is not in a writable part of the user address space."); break;
  472. case ENOBUFS :
  473. case ENOMEM : LOG_ERROR("Not enough free memory. This often means that the memory allocation is limited by the socket buffer limits, not by the system memory."); break;
  474. case EPROTO : LOG_ERROR("Protocol error."); break;
  475. case EPERM : LOG_ERROR("Firewall rules forbid connection."); break;
  476. case ENOSR:
  477. #ifdef __linux__
  478. case ESOCKTNOSUPPORT:
  479. #endif
  480. case EPROTONOSUPPORT:
  481. case ETIMEDOUT : LOG_ERROR(" Unusual error in Kernel (Timeout, No Socket Support in Kernel, Unsupported Protocol)"); break;
  482. // case ERESTARTSYS: me->Log(" Unusual error by Kernel"); break;
  483. default: LOG_ERROR(" Unhandled error in Kernel"); break;
  484. };
  485. m_bThreadStatus = TH_ENDED;
  486. }
  487. else
  488. {
  489. /*
  490. if( m_bConnectionType == 1 ){
  491. char tstr[CQUERY];
  492. #ifdef __linux__
  493. inet_ntop( AF_INET, &(((struct sockaddr_in*) &(ClientAddress ))->sin_addr ), tstr, CQUERY );//size );
  494. #else
  495. strcpy( tstr, inet_ntoa( ((struct sockaddr_in*)&ClientAddress)->sin_addr ) );
  496. //InetNtop(AF_INET, &(((struct sockaddr_in*) &(ClientAddress ))->sin_addr ), tstr, size );
  497. #endif
  498. };
  499. */
  500. int flags;
  501. flags = fcntl(ClientSocket, F_GETFL, NULL);
  502. flags |= O_NONBLOCK | O_NDELAY;
  503. // RetCode = ioctl( MainSocket, FIONBIO, (char *) &dontblock );
  504. RetCode = fcntl(ClientSocket, F_SETFL, flags);
  505. #ifdef DEBUG
  506. if (RetCode == 0)
  507. {
  508. LOG("Set N-Blocking Mode of Client Socket");
  509. }
  510. else
  511. {
  512. LOG("Can't set N-Blocking Mode of Client Socket");
  513. };
  514. LOG("Client Connection Accepted");
  515. #endif
  516. if (m_pKernelEngine)
  517. {
  518. networkClientHandler * tHandle;
  519. #ifdef DEBUG
  520. LOG("Before New Handler");
  521. #endif
  522. tHandle = m_pKernelEngine->attachNewClient(ClientSocket, &ClientAddress);
  523. #ifdef DEBUG
  524. LOG("After New Handler");
  525. #endif
  526. if (tHandle != NULL)
  527. {
  528. #ifdef DEBUG_EXTRA
  529. LOG("Handle Not NULL");
  530. #endif
  531. // tHandle->attachEngine( m_pKernelEngine );
  532. m_vHandlersPool.push_back(tHandle);
  533. }
  534. else
  535. {
  536. #ifdef DEBUG
  537. LOG_ERROR("No Client Handler Created!");
  538. #endif
  539. shutdown(ClientSocket, 2);
  540. close(ClientSocket);
  541. };
  542. }
  543. else
  544. {
  545. #ifdef DEBUG
  546. LOG_ERROR("No Kernel Attached!");
  547. #endif
  548. shutdown(ClientSocket, 2);
  549. close(ClientSocket);
  550. };
  551. };
  552. };
  553. #ifdef DEBUG
  554. LOG("Core Worker Thread Ended");
  555. #endif
  556. }
  557. bool networkServer::dispatchEvent(EVENT_CONTAINER * Evt)
  558. {
  559. if (Evt == NULL)
  560. {
  561. return false;
  562. }
  563. return true;
  564. }
  565. #undef LOG
  566. #undef LOG_ERROR