No that is windows as well. Here is my code to be tested..
FD_SET ReadSet;
FD_ZERO(&ReadSet);
FD_SET(ListenSocket, &ReadSet);
struct timeval TimeOut;
TimeOut.tv_usec = 500000; /* 0.1sec timeout */
RECEIVED = select(0, &ReadSet, NULL, NULL, &TimeOut);
while (RECEIVED > 0)
{
receivedBytes = recvfrom(ListenSocket, ReceiveBuffer, BUFFERSZ, 0, 0, 0);
//if (receivedBytes == SOCKET_ERROR) {
// wprintf(L"recvfrom failed with error %d\n", WSAGetLastError());
//}
int ierr = WSAGetLastError();
if (ierr == WSAEWOULDBLOCK)
{ // currently no data available
Sleep(50); // wait and try again
continue;
}
I read docs from:
https://docs.microsoft.com/en-us/windows/desktop/api/winsock2/nf-winsock2-select
it says:
int WSAAPI select(
int nfds,
fd_set *readfds,
fd_set *writefds,
fd_set *exceptfds,
const timeval *timeout
);
it is interesting the following: "exceptfds
An optional pointer to a set of sockets to be checked for errors."
we have: "Return Value: The select function returns the total number of socket
handles that are ready and contained in the fd_set structures, zero if the time limit expired, or SOCKET_ERROR
if an error occurred. If the return value is SOCKET_ERROR, WSAGetLastError can be used to
retrieve a specific error code". Ok I know that I have ony one socket that is ready (NOT that data is available).
I have impression that documentation suggests that is to notify that data is available for reading?????? Again the return
value will inform us that that it is zero when time limit expires! The errors in documentation are more or less in wnsock setup and do not
have anything with to do with data to be read. Or I am missing something?