Boost logo

Boost Users :

Subject: [Boost-users] Occasional blocking with tcp::socket::receive
From: Stuart Siegel (ssiegel95_at_[hidden])
Date: 2012-10-19 09:50:11


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