'ASIO async_write with empty buffer

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.



Solution 1:[1]

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.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Dave S