The async_read() and async_write() free functions are composed operations. They are implemented in terms of zero or more calls to the stream's async_read_some() or async_write_some() methods.
The member functions may not transmit or receive all data before the asynchronous operation completes. You should use the free functions if you desire that behavior.
The question's already been answered, but it's also worth mentioning that async_write_some is exactly the same function as async_send, the naming is just there for consistency since "send" applies to sockets and "write" applies to streams.
Another important point to note is that the async_write free function is what Chris Kohlhoff calls a "composed operation", and this means that even though it returns immediately, it's not safe to call another async_write until the associated handler has been called - this can cause all sorts of problems if not anticipated. The async_write_some function is lower level, and doesn't suffer from this.
发布评论
评论(2)
async_read()
和async_write()
自由函数是组合操作。它们是通过零次或多次调用流的async_read_some()
或async_write_some()
方法来实现的。在异步操作完成之前,成员函数可能不会发送或接收所有数据。如果您需要这种行为,您应该使用免费函数。
The
async_read()
andasync_write()
free functions are composed operations. They are implemented in terms of zero or more calls to the stream'sasync_read_some()
orasync_write_some()
methods.The member functions may not transmit or receive all data before the asynchronous operation completes. You should use the free functions if you desire that behavior.
问题已经得到解答,但还值得一提的是,
async_write_some
与async_send
完全相同,命名只是为了保持一致性,因为“send”适用于套接字,并且“write”适用于流。另一个需要注意的要点是,async_write 自由函数被 Chris Kohlhoff 称为“组合操作”,这意味着即使它立即返回,调用另一个 async_write< 也是不安全的。 /code> 直到调用关联的处理程序 - 如果没有预料到,这可能会导致各种问题。
async_write_some
函数级别较低,不会受到此问题的影响。进一步阅读: http://blog.think- async.com/2009/08/composed-operations-coroutines-and-code.html
The question's already been answered, but it's also worth mentioning that
async_write_some
is exactly the same function asasync_send
, the naming is just there for consistency since "send" applies to sockets and "write" applies to streams.Another important point to note is that the
async_write
free function is what Chris Kohlhoff calls a "composed operation", and this means that even though it returns immediately, it's not safe to call anotherasync_write
until the associated handler has been called - this can cause all sorts of problems if not anticipated. Theasync_write_some
function is lower level, and doesn't suffer from this.Further reading: http://blog.think-async.com/2009/08/composed-operations-coroutines-and-code.html