select() function fails in winsock

533 Views Asked by At

I am making a udp client. And I am using select function to implement timeouts :

            FD_ZERO(&stReadFDS);
            FD_SET(clientSock, &stReadFDS);
            int t = select(1, &stReadFDS, NULL, NULL, &sTimeOut);//first parameter of select is ignored in winsocks
            if (t = SOCKET_ERROR) {
                fprintf(stderr, "Call to select() failed");
                exit(1);
            }
            if (t != 0) {

                if (FD_ISSET(clientSock, &stReadFDS)) {
           //recvfrom(...)
                 }
            }

every time select func returns a SOCKET_ERROR. What am I doing wrong?

1

There are 1 best solutions below

4
On BEST ANSWER

Simple typo:

if (t = SOCKET_ERROR)

should be:

if (t == SOCKET_ERROR)