BOOST ASIO: How to use limited buffer size with async_read_until -
I use a small buffer (for example 128 bytes) and I want to use "async_read_until" TCP connections with large incoming messages (except for all 128 bytes before the delimiter)
How can this be done? The ASIO docs are not very clear what happens when the buffer provided is not large enough
here is my code for initiazation read
typedef boost :: share_ptr & Lt; Boost :: asio :: streambuf & gt; Streambuf_ptr; Streambuf_ptr inBuf (new boost :: asio :: streambuf (128)); Boost :: asio :: async_read_until (* sock, * inBuf, "\ r \ n \ r \ n", boost :: bind (my_read_handler, sock, inBuf, boost :: asio :: placeholders :: error, boost :: Asio :: placeholder :: bytes_transferred));
provided buffer is not enough, when async_read_until is complete And then invites the reader handler with the error code asio :: error :: not_found , which means that the delimiter was not found. At that point, you call some (or all) data from .consume () buffer and then async_read_until with 128-byte buffer It can be difficult to guarantee that when the delimiter is finally found, then it is in the last position in the buffer (and still, with the four-byte delimiter, you only have 124 bytes before the last). To ensure that it is best to use a large buffer and buffer consume (buffer size () - 128) in the not_found error handler That's at least 128 bytes at free time.
Comments
Post a Comment