[asio] Receiving data larger than buffer.

View: New views
3 Messages — Rating Filter:   Alert me  

[asio] Receiving data larger than buffer.

by Sajjan Kalle :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

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?
_______________________________________________
Boost-users mailing list
Boost-users@...
http://lists.boost.org/mailman/listinfo.cgi/boost-users

Re: [asio] Receiving data larger than buffer.

by Igor R :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

> 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

> 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.
_______________________________________________
Boost-users mailing list
Boost-users@...
http://lists.boost.org/mailman/listinfo.cgi/boost-users

Re: [asio] Receiving data larger than buffer.

by Sajjan Kalle :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

2009/11/11 Igor R <boost.lists@...>:
>> 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.
_______________________________________________
Boost-users mailing list
Boost-users@...
http://lists.boost.org/mailman/listinfo.cgi/boost-users