Home | Info | Community | Development | myReactOS | Contact Us
[static]
Definition at line 54 of file skelserver.c.
Referenced by StartServer().
{ SOCKADDR_IN client; SOCKET sock; HANDLE hThread; TIMEVAL timeVal; FD_SET readFD; WCHAR logBuf[256]; INT timeOut = 2000; timeVal.tv_sec = timeOut / 1000; timeVal.tv_usec = timeOut % 1000; while (!bShutdown) { INT selRet = 0; FD_ZERO(&readFD); FD_SET(listeningSocket, &readFD); selRet = select(0, &readFD, NULL, NULL, &timeVal); if (selRet > 0) { if (!bShutdown || FD_ISSET(listeningSocket, &readFD)) { INT addrSize = sizeof(SOCKADDR_IN); sock = accept(listeningSocket, (SOCKADDR*)&client, &addrSize); if (sock != INVALID_SOCKET) { _swprintf(logBuf, L"Accepted connection to %s server from %S:%d", lpName, inet_ntoa(client.sin_addr), ntohs(client.sin_port)); LogEvent(logBuf, 0, 0, LOG_FILE); _swprintf(logBuf, L"Creating worker thread for %s", lpName); LogEvent(logBuf, 0, 0, LOG_FILE); if (!bShutdown) { hThread = CreateThread(0, 0, lpService, (void*)sock, 0, NULL); if (hThread != NULL) { CloseHandle(hThread); } else { _swprintf(logBuf, L"Failed to start worker thread for the %s server", lpName); LogEvent(logBuf, 0, 0, LOG_FILE); } } } else { LogEvent(L"accept failed", WSAGetLastError(), 0, LOG_ERROR); } } } else if (selRet == SOCKET_ERROR) { LogEvent(L"select failed", WSAGetLastError(), 0, LOG_ERROR); } } }