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.

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