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
996 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

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

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…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

696 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