Boost logo

Boost Users :

Subject: [Boost-users] [asio] synchronous read from sslstream with unknown length
From: Torsten Müller (irrlicht67_at_[hidden])
Date: 2013-06-25 08:13:42


I have a problem reading HTTP synchronously from a sslstream.
 
If the HTTP server specifies a content-length header it works fine, I read exactly the given length and have a complete answer.
 
If I haven't got a content-length header from the server I use an algorithm like this:
 
    asio::ssl::stream<asio::ip::tcp::socket&>* m_pSslStream;
    // ... initializations ...
    // ... read HTTP headers ...
    // (get no content-length here)
    // read the HTTP body
    asio::streambuf sb;
    system::error_code error;
    size_t n;
    while ((n = asio::read(*m_pSslStream, sb,
                             asio::transfer_exactly(1024), error)) > 0)
    {
        // ... handle contents ...
    }
 
This should read 1k-blocks until there are no more bytes in the stream. The last call to the read-function should return less than 1024 bytes and an error code. Indeed this happens, exactly as specified, but the last call to the read-function doesn't return until a long timeout is reached, about one minute or more. What's the reason for this?
 
I tried also other things: transfer_at_least() or transfer_all(), also the read_some-method of the sslstream class. All show exactly the same behaviour (think, they all use the same code).
 
What can I do to avoid this timeout at the end? Is this related to SSL? I can't remember that I had problems with this on non-SSL streams.
 
T.M.
 

Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net