asio:多个待处理的async_read? [英] asio : multiple pending async_read?

查看:70
本文介绍了asio:多个待处理的async_read?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

async_read在收到请求的字节数时调用回调.这可能意味着多次调用async_read_some.

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

在文档中,指定最多可以有一个未决的async_read_some.必须在发出下一个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.

那async_read呢?可以将多个async_read排队吗?如果是,执行顺序是否保证得到保留?

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

推荐答案

根据

此操作是通过对流的 async_read_some 函数的零次或多次调用来实现的,被称为组合操作.程序必须确保该流完成之前,该流不执行其他任何读取操作(例如 async_read ,该流的 async_read_some 函数或任何其他执行读取的组合操作).

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.

这意味着在调用完成处理程序(回调)之前,您无法在同一流上开始任何进一步的 async_read 操作-当提供的缓冲区为填充,满足完成条件或发生某些错误.

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.

您不清楚排队"多个 async_read 操作的含义.实施 async_read 操作序列的方式是通过在完成处理程序中启动下一个操作.

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.

这篇关于asio:多个待处理的async_read?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆