Click here to Skip to main content
15,891,136 members

Very Slow Winsock2 recv

Revision 2
Hello,

I'm developing a simple HTTP client in C++ (using VS2010) and I'm using an apache located at localhost for testing.

While the send'ing code workes like a charm, the recv takes up to 6-7 seconds to receive the whole message (500 bytes or so).

The actual question: how come is recv so slow? (I'm also setting TCP_NODELAY on my socket)

My implementation of the receiving routine:
C++
int HttpClient::_receive()
{
    char buffer[1024];
    int  iReceivedBytes = 0;

    // init the buffer to an empty string
    buffer[0] = 0;

    while(1)
    {
        iReceivedBytes = recv(m_socket, buffer, 1024, 0);
        if (iReceivedBytes > 0)
        {
            // m_response is a member std::string
            m_response.append(buffer, iReceivedBytes);
        } else
           break;
    }

    // parse message
    return _parseMessage();
}


Edit: When testing the apache with a browser it takes less than 1 second to perform the same request.

Thanks,
Alex
Posted 24-Aug-12 6:41am by Alex Culea.