Winsock select error 10038, bind and listen successful

1.4k Views Asked by At

I'm trying to use Winsock's select() function. However, despite successfully creating a socket, binding it to a port and started it listening, select is failing with error 10038 ("not a socket"). I can confirm with TCPView that the socket is indeed listening on port 8080, so I'm not sure why I'm getting this error.

This is some test code that I've added just after successfully using listen().

    fd_set readfds;
    SOCKET client_socket[2], s;
    int act, max_clients = 2;

    while (true)
    {
        FD_ZERO(&readfds);
        FD_SET(this->sock, &readfds);

        for (int i = 0; i < max_clients; i++) 
        {
            s = client_socket[i];
            if(s > 0)
            {
                FD_SET(s, &readfds);
            }
        }

        act = select(0, &readfds, NULL, NULL, NULL);

        if (act == SOCKET_ERROR) 
        {
            printf("Select failed: %d" , WSAGetLastError());
        }
    }

I've taken out a break that would usually come after the printf(), just so I could see it easier in TCPView. The state is reported by TCPView as "LISTENING", as expected. this->sock is the SOCKET used by bind() and listen().

1

There are 1 best solutions below

0
On

One of the FDs you are selecting on isn't a socket FD.