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