Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Windows sockets: WSAWaitForMultipleEvents returning WSA_WAIT_EVENT_0, on an FD_READ event, with no data available to read.

Posted on 2006-10-26
1
Medium Priority
?
1,033 Views
Last Modified: 2012-06-21
Hi,
I'm writing a simple client - server communication application.  My question here is in regards to the server side.

After the client establishes a connection, it then writes 8 bytes.

The following (server side) code section successfully receives the 8 bytes.  The problem is that future calls to WSAWaitForMultipleEvents seem to all return signalled, even though there is no data to read.  To illustrate, I put a for-next loop around the same WSAWaitForMultipleEvents...recv sequence.  The first iteration through the code successfully reads the 8 bytes, but on the 2nd iteration through, the WSAWaitForMultipleEvents call still returns signalled, even though the FD_READ event should have been cleared by the recv call.  See the output below.
Any thoughts on what the problem is would be greatly appreciated.  This is the only worker thread in the application.  

            int iError=WSAEventSelect(m_Sockets[ClientIndex], m_Events[ClientIndex], FD_READ);
            if (iError) Message6(RED,"WSAEventSelect Failed"); else Message6(GREEN,"WSAEventSelect Successful");

            DWORD dwResult;
            for (int k=1; k<4; k++)
            {
                  Message6(BLACK,"Iteration #%d",k);
                  dwResult = WSAWaitForMultipleEvents(1,&m_Events[ClientIndex],FALSE,500,FALSE);
                  if (dwResult==WSA_WAIT_EVENT_0)
                  {      Message6(BLACK,"First WSAWaitForMultipleEvents returning WSA_WAIT_EVENT_0 (signalled).  mask=%x",FD_READ);

                        int iResult = recv(m_Sockets[ClientIndex], (char*)(&dData), 8, 0);
                        if (iResult == SOCKET_ERROR)
                        {
                              int iErr=WSAGetLastError();
                              if (iErr==WSAEWOULDBLOCK)
                                    Message6(BLACK,"WSAEWOULDBLOCK on receive.");
                              else
                                    DisplayWinSockErrorMessage("recv error: ",iErr);
                        }
                        else
                        {
                              Message6(GREEN,"Just received %d bytes of data. %f",iResult,dData);
                        }
                  }

            }


2006.10.26 14:57:59.90851 WSAEventSelect Successful
2006.10.26 14:57:59.90852 Iteration #1
2006.10.26 14:57:59.91472 First WSAWaitForMultipleEvents returning WSA_WAIT_EVENT_0 (signalled).  mask=1
2006.10.26 14:57:59.91475 Just received 8 bytes of data.
2006.10.26 14:57:59.91476 Iteration #2
2006.10.26 14:57:59.91477 First WSAWaitForMultipleEvents returning WSA_WAIT_EVENT_0 (signalled).  mask=1
2006.10.26 14:57:59.91478 WSAEWOULDBLOCK on receive.
2006.10.26 14:57:59.91479 Iteration #3
2006.10.26 14:57:59.91480 First WSAWaitForMultipleEvents returning WSA_WAIT_EVENT_0 (signalled).  mask=1
2006.10.26 14:57:59.91481 WSAEWOULDBLOCK on receive.
0
Comment
Question by:dcShaver
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 48

Accepted Solution

by:
AlexFM earned 2000 total points
ID: 17814649
0

Featured Post

Tech or Treat!

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The following diagram presents a diamond class hierarchy: As depicted, diamond inheritance denotes when two classes (e.g., CDerived1 and CDerived2), separately extending a common base class (e.g., CBase), are sub classed simultaneously by a fourt…
In Easy String Encryption Using CryptoAPI in C++ (http://www.experts-exchange.com/viewArticle.jsp?aid=1193) I described how to encrypt text and recommended that the encrypted text be stored as a series of hexadecimal digits -- because cyphertext may…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses

610 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question