Discussion:
[asio] Receiving data larger than buffer.
Sajjan Kalle
2009-11-11 13:24:44 UTC
Permalink
Hi, I have a few questions regarding asio, and the network sockets in
particular. I'm using TCP sockets to transfer data across a network.
The problem I have is when data that is larger than the receive
buffer. In this case num bytes reported == receive buffer size,
however, is there a way to distinguish the case when I receive exactly
buffer size amounts of data, and when the case when there's more left
to complete the transfer?

How does asio handle transfer of really large buffers? Will it
dispatch it client side in receive buffer sized chunks as it enters,
or will it wait for the entire payload to enter some internal buffer
before dispatching?
Igor R
2009-11-11 13:33:36 UTC
Permalink
Post by Sajjan Kalle
however, is there a way to distinguish the case when I receive exactly
buffer size amounts of data, and when the case when there's more left
to complete the transfer?
You can use socket::available()
http://www.boost.org/doc/libs/1_40_0/doc/html/boost_asio/reference/basic_stream_socket/available.html
Post by Sajjan Kalle
How does asio handle transfer of really large buffers? Will it
dispatch it client side in receive buffer sized chunks as it enters,
or will it wait for the entire payload to enter some internal buffer
before dispatching?
IIRC, the current implementation of ASIO (at least in windows) just
supplies your buffer(s) to the OS API that performs the actual i/o, so
no additional copying occurs.
Sajjan Kalle
2009-11-24 17:33:48 UTC
Permalink
Post by Igor R
Post by Sajjan Kalle
however, is there a way to distinguish the case when I receive exactly
buffer size amounts of data, and when the case when there's more left
to complete the transfer?
You can use socket::available()
http://www.boost.org/doc/libs/1_40_0/doc/html/boost_asio/reference/basic_stream_socket/available.html
I've encountered cases where socket::available() > 0 but the number of
bytes transfered is less than the size in the buffer. I presume this
means that more data has been sent on the socket, but as a part of
another send operation, which sadly brings me back to the original
problem. Is there a clean way to differentiate between the case where
the send operation just happened to be exactly the same amount of
bytes as the buffer, and there's nothing left for that particular
transfer but still more data available on the socket, and the case
where there's more data available on the socket but it being part of
the same send operation.

Loading...