void SocketServer::run() { #ifdef TCP // Start Listening for clients listen(sockfd, maxUser); logger->info("[INFO] SOCKET SERVER listening ..."); while (sockfd > 1) { //wait for clients Blocking Call connfd = accept(sockfd, (struct sockaddr *) &client_addr, (socklen_t *)&client_len); if (connfd < 1) { logger->error( "[ERROR] SOCKET SERVER Failed to accept connection."); close(connfd); } else { int result = send(connfd, buffer, sizeof(sendBuff) , 0); if (result < 0) logger->error("[ERROR] SOCKET SERVER Buffer Dispatch Error."); close(connfd); } } #else while (sockfd > 1 && getFlag() ) { //logger->info( "[INFO] SOCKET SERVER Ready to Receive"); //Blocking Call char* bufferRx = recvMsg(); std::thread recvThread( &SocketServer::receiveRequest, this , client_addr, bufferRx ); recvThread.detach(); //Sanity De-reference bufferRx=NULL; //Waiting Before Receiving another //std::unique_lock<std::mutex> lck(mtx); //cv.wait(lck); } #endif logger->info( "[INFO] SOCKET SERVER End Run"); }
void *recvFunction(){ recvThread(); // while(1){} // for testing only }