Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

boost.asio's socket's receive/send functions are bad?

Data may be read from or written to a connected TCP socket using the receive(), async_receive(), send() or async_send() member functions. However, as these could result in short writes or reads, an application will typically use the following operations instead: read(), async_read(), write() and async_write().

I don't really understand that remark as read(), async_read(), write() and async_write() can also end up in short writes or reads, right?
Why are those functions not the same?
Should I use them at all?
Can someone clarify that remark for me?

like image 509
the_drow Avatar asked May 18 '10 22:05

the_drow


1 Answers

The read, async_read, write, and async_write are composed functions that call the class functions multiple times until the requested number of bytes is transmitted. They are included by the library as a convenience. Otherwise, every developer would need to implement the same logic.

The class functions wrap the underlying OS functions directly, which basically state in the documentation: these functions may return before all of the bytes are transmitted.

In most cases, you should use the free (composed) functions to transmit data.

like image 93
Dan Avatar answered Sep 28 '22 04:09

Dan