I am having an issue with an overzealous select() call. I works as expected until I send a single UDP message to my socket. Then it reports that there is activity even after the application performs a read on the socket.

Is there any special way to "clear" the internal state of the socket so that it select() understands that the socket has been serviced?

Here's the snippet of code that I am using for the select():
Code:
UINT CUdpComm::MonitorReadEvent()
{
   fd_set savefds;
   FD_ZERO(&savefds);
   FD_SET(m_server->GetHandle(), &savefds);    // GetHandle() returns a SOCKET

   while (m_server->Connected())
   {
      struct timeval timeout = {1, 0};
      fd_set readfds = savefds;
      int sel = ::select(m_server->GetHandle(), &readfds, 0, 0, &timeout);

      if (sel == 0) continue;   // timeout

      if (sel > 0 && FD_ISSET(m_server->GetHandle(), &readfds))
      {
         ::PostMessage(m_wnd, WM_USER_COMMPORT, 0, 0);
      }

      if (sel == SOCKET_ERROR)  AfxMessageBox("Error with select().");
   }

   return 0;
}
Above, the m_server is a CUdpSocket object. Here's how it is receiving data, when the callback routine that is associated with WM_USER_COMMPORT is called:
Code:
int CUdpSocket::Receive(BYTE buf[], short bufSize, CString& fromAddress, int& fromPort)
{
   sockaddr_in addr;
   socklen_t addrLen = sizeof(addr);

   int rtn = recvfrom(m_socket, (char*) buf, bufSize, 0, (sockaddr*) &addr, (socklen_t*) &addrlen);

   if (rtn >= 0)
   {
      fromAddress = inet_ntoa(addr.sin_addr);
      fromPort = ntohs(addr.sin_port);
   }

   return rtn;
}
I've verified that the UDP message is indeed being received (obviously in its entirety... it is only 6 bytes long), however I cannot explain why the select() is telling me again and again that there is activity on the socket... even after a read is performed, and no more messages are being sent by the client. This hoses my application up because when it attempts the recvfrom(), it blocks... and then my app is deadlocked.

Any ideas what M$ VC++ expects of my application? Under Linux, the underlying principles shown above would work.