|
Boost Users : |
Subject: Re: [Boost-users] Occasional blocking with tcp::socket::receive
From: Stuart Siegel (ssiegel95_at_[hidden])
Date: 2012-10-25 09:37:07
I have read the documentation :-)
My understanding is that it's blocking if there's no data left to be read and you ask it to read from the socket. In my case, the server has sent the data and it's there waiting for it to read. I've confirmed this via wireshark and, as I mentioned, the plain POSIX call to read (which is also blocking by the way) works as expected.
________________________________
From: nullable.type <nullable.type_at_[hidden]>
To: boostusers_at_[hidden]
Cc: "boost-users_at_[hidden]" <boost-users_at_[hidden]>; boost-users_at_[hidden]; ssiegel95_at_[hidden]
Sent: Thursday, October 25, 2012 3:34 AM
Subject: Re: [Boost-users] Occasional blocking with tcp::socket::receive
Hi
Read the documentation:
http://www.boost.org/doc/libs/1_51_0/doc/html/boost_asio/reference/basic_stream_socket/receive/overload1.html
A call to boost::asio::ip::tcp::socket::receive(..) IS a blocking call. If you wannt to avoid blocking, just use the async_* functions.
Cheers,
Simon
On Friday, October 19, 2012 3:50:11 PM UTC+2, Stuart Siegel wrote:
The call to receive below will occasionally hang. All interactions are synchronous and single threaded. Things work perfectly if I use the alternative <sys/socket.h> (POSIX) implementation under the #else. Since I'm pretty new to boost::asio, I must be doing something wrong but after many hours of trying different things, I'm still stuck. Any advice would be appreciated. #if 1
namespace bas = boost::asio; remaining = X //(something typically about 5000 bytes of char data) bas::streambuf b;
bas::streambuf::mutable_ buffers_type bufs = b.prepare(1024); while (remaining > 0) { size_t n = sock.receive(bufs); //<-------------this blocks every so often remaining -= n; for ( bas::buffers_iterator<bas:: streambuf::mutable_buffers_ type, char> it = bas::buffers_begin(bufs); it < (bas::buffers_begin(bufs) + n); it++ ) qba.append(*it); }
#else //this works perfectly in the 250000 or so test calls I've hit it with char buf[1024]; while (remaining > 0) { n = read( sock, buf, min( sizeof(buf), remaining ) ); remaining -= n; for (int i = 0 ; i < n; i++ ) qba.append(buf); }
#endif
>
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