3

Boost asio implements proactor design pattern baded on ACE proactor.

I understand why we need async read. Hovewer, I'm a confused with async write.

  1. Why we need is async write? Is it useful for TCP/UDP connection too (can write to TCP/UDP socket take time)?
  2. Can I mix async read with sync write?
dimba
  • 26,717
  • 34
  • 141
  • 196

1 Answers1

4

1) Why we need is async write? Is it useful for TCP/UDP connection too (can write to TCP/UDP socket take time)?

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) 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.

Sam Miller
  • 23,808
  • 4
  • 67
  • 87
  • 1. Is write to TCP socket for example, is longer than actions involved in async write (creating buffer, sometimes allocating memory chunk to be alive while write, queuing callback etc.) – dimba Apr 05 '11 at 17:15
  • 1
    2. I don't understand your answer - should or should not be mixed? :) – dimba Apr 05 '11 at 17:16
  • 2. And can you please explain why? – dimba Apr 07 '11 at 04:56
  • @dimba the explanation for answer #2 is the same as answer #1. Mixing synchronous operations with asynchronous is not desirable when using the proactor design pattern. Doing so would require explicit threads to avoid blocking the epoll reactor event loop. – Sam Miller Apr 07 '11 at 12:57
  • Ok, I get it. So in order to receive async read I'm "forced" to use async write. – dimba Apr 10 '11 at 16:35