int main(int argc, char **argv) { VARZExecutor_t executor; int udp_fd, tcp_fd; fd_set readfds; udp_fd = setupUDPSocketAndReturnFD(); tcp_fd = setupTCPSocketAndReturnFD(); VARZExecutorInit(&executor, EXECUTOR_HT_SIZE); while (1) { FD_ZERO(&readfds); FD_SET(udp_fd, &readfds); FD_SET(tcp_fd, &readfds); select(MAX(udp_fd, tcp_fd)+1, &readfds, NULL, NULL, NULL); if (FD_ISSET(udp_fd, &readfds)) { handleUDPPacket(udp_fd, &executor); } else if (FD_ISSET(tcp_fd, &readfds)) { handleNewTCPConnection(tcp_fd, &executor); } } VARZExecutorFree(&executor); return 0; }
void Server::run() { writeToLog(L"Main Network Thread started."); sf::Clock clock; while(Run) { if(!isFull() && !Listening) { Listening = true; AccepterThread->launch(); } sf::Packet packet; sf::IpAddress ip; sf::Uint16 port; if(Socket.receive(packet, ip, port) == sf::Socket::Done) { if(handleUDPPacket(packet, ip, port)) { //Success } else { std::wstringstream ss; ss << L"Packet error on {YDUDP Socket}."; writeToLog(ss.str()); } } } }