Boost logo

Boost Users :

Subject: Re: [Boost-users] boost::asio determining end of stream,
From: Igor R (boost.lists_at_[hidden])
Date: 2010-02-14 10:49:28


> I am using boost:asio sync socket to upload file to server. At the end of upload, server send response back which can varying length and format. I need to read this response, considering that I haven't found a way to know how much data is available for reading, my call get blocked on some of the response.
>
> I Was wondering if there is a way to know one or more of the following.
>
> Is there condition I can pass to the read_until() call so that it read all the available response in one call?

No. You can read "all the available response" using
tcp::socket::read_some()/async_read_some(), but this would be the data
available at time of the read operation - next moment some more data
might arrive.

> Is there a way to know that how much data remaining to be read?

tcp::socket::available()
http://www.boost.org/doc/libs/1_42_0/doc/html/boost_asio/reference/basic_stream_socket/available.html

> Is there a way that my call time out when there is no data?

You can implement time-out using asynchronous read and
asio::deadline_timer, just like in the following example:
http://www.boost.org/doc/libs/1_42_0/doc/html/boost_asio/example/timeouts/stream_receive_timeout.cpp


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