Frohdoh 0 Newbie Poster

hello,
we use an async. socket for message handling:

WSAAsyncSelect(s, g_iohwnd, SOCKET_IO_MESSAGE, (FD_ACCEPT | FD_CONNECT | FD_READ | FD_CLOSE | FD_WRITE));

socket messages are directly handled in the g_iohwnd window message loop. Everything works fine beside:

status = recv(
            m_clsocket, 
            (char *)(InputData.m_buffer + InputData.m_buffer_size), 
            RECV_SIZE, 
            0);

        if(status == 0)
        {
            Console.ErrorMsg("recv: status = 0, socket closed", status);
            CloseClient();
            return;        
        }
        else if(status == SOCKET_ERROR)
        {
            status = WSAGetLastError();
            if(status != WSAEWOULDBLOCK)
            {
                Console.ErrorMsg("recv failed: reason %d", status);
                CloseClient();
                return;     
            }
            else
            {                
                break;
            }
        }

-> server sends data
-> server close the connection
-> message loop receive FD_READ but recv returns 0 (gracefully closed socket)

this happens mainly with slow connections. The data send directly before closing the socket is lost ... what can I do?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.