asio : multiple pending async_read?

落爺英雄遲暮 提交于 2019-12-12 18:22:58

问题


async_read calls the callback when the requested amount of bytes have been received. This may imply multiple calls to async_read_some.

In the documentation it is specified that there can be at most one pending async_read_some. The callback has to be called before the next async_read_some may be issued.

What about the async_read ? Can multiple async_read be queued ? If yes, is the order of execution guaranteed to be preserved ?


回答1:


According to the documentation of async_read(...)

This operation is implemented in terms of zero or more calls to the stream's async_read_some function, and is known as a composed operation. The program must ensure that the stream performs no other read operations (such as async_read, the stream's async_read_some function, or any other composed operations that perform reads) until this operation completes.

That would imply that you can't start any further async_read operations on the same stream until the completion handler (the callback) is called -- this should be only once, when the provided buffer is filled, completion condition is satisfied, or some error occurs.

You're not entirely clear on what you mean by "queueing" multiple async_read operations. The way you would implement a sequence of async_read operations would be by starting the next operation in the completion handler.



来源:https://stackoverflow.com/questions/37098594/asio-multiple-pending-async-read

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!