Saturday, June 22, 2013

boost::asio, synchronous HTTP read on sslstream

Newsgroup: comp.lang.c++

Subject: boost::asio, synchronous HTTP read on sslstream

From: Torsten Mueller <irrlicht67@...>

Date: Sat, 22 Jun 2013 13:48:20 +0200



I have a problem reading on a sslstream. If the content-length is

specified it works fine, I read exactly the given length and have a

complet answer. If I didn't get 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 before 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.



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.







via Usenet Forums - Usenet Search,Free Usenet - comp.lang.c++ http://www.pocketbinaries.com/usenet-forums/showthread.php?23909-boost-asio-synchronous-HTTP-read-on-sslstream&goto=newpost

View all the progranning help forums at:

http://www.pocketbinaries.com/usenet-forums/forumdisplay.php?128-Coding-forums

No comments:

Post a Comment