Al Kurlansky
Al Kurlansky

Reputation: 307

boost::asio::async_write() versus boost::asio::write()

Is there any advantage in terms of the time it takes to get the data buffer out onto the wire if you use

boost::asio::write(m_socket, asio::buffer(dataOut_, len), asio::transfer_all());

instead of

boost::asio::async_write(m_socket, boost::asio::buffer(hbs, sizeof(hbs)),
                         boost::bind(&Client::handle_pulse, this,
                         boost::asio::placeholders::error,
                         boost::asio::placeholders::bytes_transferred));

Upvotes: 9

Views: 3771

Answers (1)

Some programmer dude
Some programmer dude

Reputation: 409442

The big difference is that the normal write can block until all is written, while async_write returns immediately and calls a callback when either all data is written or an error occurs.

I doubt there is any noticeable difference in time from call to the data actually being sent over the wire.

Upvotes: 2

Related Questions