ASIO async_write with empty buffer

Viewed 92

What happens when an ASIO async_write is invoked with zero bytes in the outgoing buffer?

Example:

// Assume data is a member with appropriate lifetime for duration of handler, but data.size() == 0

boost::asio::async_write(stream_,
    boost::asio::buffer(data.data(), data.size()),
    beast::bind_front_handler(&MyClass::on_write, this->shared_from_this()));

Does the on_write() handler get invoked immediately, never get called, or is it undefined what happens? Nothing in the docs seems to provide a good answer.

1 Answers

In earlier releases, the handler would be invoked once the socket became writable. This is similar to the null_buffers case. Those classes are deprecated, but I believe the behavior is still present.

Related