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
1,007 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 500 total points
ID: 17814649
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

687 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