-
- /* don't call FD_ISSET if bShutDown flag is set */
- if ((! bShutDown) || (FD_ISSET(ListeningSocket, &ReadFDS)))
- {
- Sock = accept(ListeningSocket, (SOCKADDR*)&Client, &nAddrSize);
- if (Sock != INVALID_SOCKET)
- {
- _stprintf(buf, _T("Accepted connection to %s server from %s:%d\n"),
- Name, inet_ntoa(Client.sin_addr), ntohs(Client.sin_port));
- LogEvent(buf, 0, FALSE);
- _stprintf(buf, _T("Creating new thread for %s\n"), Name);
- LogEvent(buf, 0, FALSE);
-
- hThread = CreateThread(0, 0, Service, (void*)Sock, 0, &ThreadID);
-
- /* Check the return value for success. */
- if (hThread == NULL)
- {
- _stprintf(buf, _T("Failed to start worker thread for "
- "the %s server....\n"), Name);
- LogEvent(buf, 0, TRUE);
- }
-
- WaitForSingleObject(hThread, INFINITE);
-
- CloseHandle(hThread);
- }
- else
- {
- LogEvent(_T("accept failed\n"), 0, TRUE);
- return;
- }
- }
+ else if (SelRet > 0)
+ {
+ /* don't call FD_ISSET if bShutDown flag is set */
+ if ((! bShutDown) || (FD_ISSET(ListeningSocket, &ReadFDS)))
+ {
+ Sock = accept(ListeningSocket, (SOCKADDR*)&Client, &nAddrSize);
+ if (Sock != INVALID_SOCKET)
+ {
+ _stprintf(buf, _T("Accepted connection to %s server from %s:%d\n"),
+ Name, inet_ntoa(Client.sin_addr), ntohs(Client.sin_port));
+ LogEvent(buf, 0, FALSE);
+ _stprintf(buf, _T("Creating new thread for %s\n"), Name);
+ LogEvent(buf, 0, FALSE);
+
+ hThread = CreateThread(0, 0, Service, (void*)Sock, 0, &ThreadID);
+
+ /* Check the return value for success. */
+ if (hThread == NULL)
+ {
+ _stprintf(buf, _T("Failed to start worker thread for "
+ "the %s server....\n"), Name);
+ LogEvent(buf, 0, TRUE);
+ }
+
+ WaitForSingleObject(hThread, INFINITE);
+
+ CloseHandle(hThread);
+ }
+ else
+ {
+ LogEvent(_T("accept failed\n"), 0, TRUE);
+ return;
+ }
+ }
+ }