Proactor和异步写 [英] Proactor and async write
问题描述
Boost asio 实现了原型设计模式 ACE proactor 。
Boost asio implements proactor design pattern baded on ACE proactor.
我明白为什么我们需要异步读。 Hovewer,我对异步写入感到困惑。
I understand why we need async read. Hovewer, I'm a confused with async write.
- 为什么我们需要异步写?
它是有用的TCP / UDP连接太(可以写入TCP / UDP套接字需要时间)? - 我可以混合异步读取与同步写入吗?
推荐答案
1)为什么我们需要的是异步写?它是有用的TCP / UDP连接太多(可以
写入TCP / UDP套接字花费时间)?
1) Why we need is async write? Is it useful for TCP/UDP connection too (can write to TCP/UDP socket take time)?
异步写因为与异步读取的原因相同。使用同步写操作时,调用阻塞,直到所有数据都已传输。由于多种原因,这是不希望的。主要是为了在不使用显式线程的情况下实现并发,这是 proactor design pattern 。
Asynchronous write is needed for the very same reasons as asynchronous read. When using synchronous write operations, the calls block until all data has been transmitted. This is not desirable for a number of reasons. Primarily to achieve concurrency without use of explicit threads, this is the basis of the proactor design pattern.
2)我可以混合异步读取与同步写吗? p>
2) Can I mix async read with sync write?
是的,他们可以和应该混合。这将是一个非常奇怪的设计,使用异步读操作,但同步写操作。
Yes, they can and should be mixed. It would be a very odd design to use asynchronous read operations, yet synchronous write operations.
这篇关于Proactor和异步写的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!