Boost logo

Boost Users :

Subject: Re: [Boost-users] Why do socket::receive() and socket::async_receive() have different return types?
From: Richard Hodges (hodges.r_at_[hidden])
Date: 2018-06-14 14:53:07


Async operations don't have a "result" until the handler has been scheduled
for execution. The result of the operation is sent to the handler.

Therefore, returning a size_t would be meaningless for the async versions
of the operations since the number of bytes sent or received is not known
when the call returns.

The non-async versions block until there is a result, so they are able to
return it directly.

On Thu, 14 Jun 2018 at 15:49, Álvaro Cebrián Juan via Boost-users <
boost-users_at_[hidden]> wrote:

> From the documentation I can see that socket::receive()
> <https://www.boost.org/doc/libs/1_58_0/doc/html/boost_asio/reference/basic_datagram_socket/receive.html>
> returns a variable of type "std::size_t", while the asynchronous version
> socket::async_receive()
> <https://www.boost.org/doc/libs/1_58_0/doc/html/boost_asio/reference/basic_datagram_socket/async_receive.html>
> returns "void". This is also true for socket::send()
> <https://www.boost.org/doc/libs/1_58_0/doc/html/boost_asio/reference/basic_datagram_socket/send.html>
> and socket::async_send()
> <https://www.boost.org/doc/libs/1_58_0/doc/html/boost_asio/reference/basic_datagram_socket/async_send.html>
> .
> I was expecting that they would have the same return types, so there might
> be a good reason behind.
>
> I would be grateful if someone can shed some light on this.
>
> Thank you.
>
> Álvaro
> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]
> https://lists.boost.org/mailman/listinfo.cgi/boost-users
>



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