cwinsockwinsock2posix-select

select() function fails in winsock


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?


Solution

  • Simple typo:

    if (t = SOCKET_ERROR)
    

    should be:

    if (t == SOCKET_ERROR)