select returns 10038 on 64 bit system
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: select returns 10038 on 64 bit system

Hybrid View

  1. #1
    Join Date
    Mar 2011
    Posts
    2

    Question select returns 10038 on 64 bit system

    The following code has been running for several years without problems on 32 bit systems. We are now attempting to build the code for a 64 bit Windows 7 system. The select statement is returning a 10038 error. The socket was ok in the "bind" and "listen" function calls. Perhaps the structure being built by FD_SET is aligned improperly? Any ideas?

    int rc = 0, temprc = 0;
    SOCKET AcceptSocket = 0, objListenSocket = 0;
    struct sockaddr_in socketinfo, acceptinfo;
    int iLength;
    struct timeval stTimeout;
    fd_set structReadFDS;
    char cLogBuffer[150];


    // Create the listening socket
    objListenSocket = socket (AF_INET, SOCK_STREAM, 0);
    if (objListenSocket == INVALID_SOCKET)
    {
    rc = XSRV_COULDNT_CREATE_SOCKET;
    temprc = WSAGetLastError();
    goto exit1;
    }



    // Bind the socket
    // Port number must be in Network byte order (big endian)
    memset (&socketinfo, '\0', sizeof(socketinfo));
    socketinfo.sin_family = AF_INET;
    socketinfo.sin_port = htons(47809);
    socketinfo.sin_addr.s_addr = INADDR_ANY;
    rc = bind(objListenSocket, (struct sockaddr *)&socketinfo, sizeof(socketinfo));
    if (rc == SOCKET_ERROR)
    {
    temprc = WSAGetLastError();
    rc = XSRV_COULDNT_BIND_SOCKET;
    goto exit1;
    }

    // Listen on the socket for a connection, backlog = 5 deep (the max)
    rc = listen(objListenSocket, SOMAXCONN);
    if (rc == SOCKET_ERROR)
    {
    temprc = WSAGetLastError();
    rc = XSRV_COULDNT_LISTEN_ON_SOCKET;
    goto exit1;
    }

    // Use select to determine if there is any data on the listening
    // socket. If not, don't try to accept. This keeps the accept from
    // blocking.
    // Initialize the select structure with listening socket.
    FD_ZERO(&structReadFDS);
    FD_SET(objListenSocket, &structReadFDS);

    // Select timesout in 1/2 a second
    temprc = select(NULL, &structReadFDS, NULL, NULL, &stTimeout);
    // If error
    if (temprc == SOCKET_ERROR)
    {
    temprc = WSAGetLastError();
    rc = XSRV_COULDNT_SELECT;
    goto exit2;
    }

  2. #2
    Join Date
    May 2001
    Location
    Germany
    Posts
    1,110

    Re: select returns 10038 on 64 bit system

    as far as I can see, stTimeout is not initialized. May this cause a problem? The rest of the code looks ok to me.

  3. #3
    Join Date
    Mar 2011
    Posts
    2

    Re: select returns 10038 on 64 bit system

    Sorry, I left out the initialization of stTimeout when I copied the code snippet. It is being initialized. The select simply fails to work on the 64 bit system.

  4. #4
    Join Date
    May 2001
    Location
    Germany
    Posts
    1,110

    Re: select returns 10038 on 64 bit system

    can you see that the socket is created correctly. Try using netstat or TcpView to see that the socket is correctly opened. I understand that bind() and listen() succeed, but I would make sure I can "see" the socket.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center