Valhalla Legends Archive

Programming => General Programming => Topic started by: iago on July 02, 2003, 04:35 AM

Title: Nonblocking Sockets
Post by: iago on July 02, 2003, 04:35 AM
I think I already know the answer to this, so I'm just confirming:

I'm using nonblocking sockets, and when I try recieving data it returns SOCKET_ERROR with the error code WSAEWOULDBLOCK.  This is the code I'm using:
void WS::SetSocketBlocking(DWORD Block)
{
   if(ioctlsocket(s, FIONBIO, &Block) == SOCKET_ERROR)
   {
      if(ErrorCallback)
         ErrorCallback("Error setting socket blocking (ioctlsocket)", WSAGetLastError());
   }
}


Anyway, I'm just assuming that I should just ignore this error because it's just telling me that there just wasn't any data waiting, but I'm just making sure that this isnt' a horrible, horrible error.

Thanks!

-iago
Title: Re:Nonblocking Sockets
Post by: DarkMinion on July 02, 2003, 07:38 AM
WSAEWOULDBLOCK should just be ignored, yes, it is not a horrible, horrible error  :P


      if(dwWaitResult == WAIT_OBJECT_0 && bBNETConnected){
         int iRecvLen = recv(sBNET, szRecvBuffer, sizeof(szRecvBuffer), 0);
         if(!iRecvLen || iRecvLen == SOCKET_ERROR && WSAGetLastError() != WSAEWOULDBLOCK)
            break;
         ParseBNET(szRecvBuffer, iRecvLen);
      }
Title: Re:Nonblocking Sockets
Post by: Yoni on July 02, 2003, 09:19 AM
WSAEWOULDBLOCK means "your call succeeded now, but it might fail later since the action you requested hasn't completed yet." Usually you can ignore it safely.
Title: Re:Nonblocking Sockets
Post by: iago on July 02, 2003, 11:51 AM
All right, thanks! :-)