1

I am using boost::asio to make server. But I want to know asio's mechanism. Let's start with some pseudo-code:

Pseudo Code (server)

async_read_some(MY::read1);

MY::read1() {
    async_read_some(MY::read1);
    async_write(someData);  // someData : "ABCD"
}

Scenario

  • client:

    1. send data to server.

    2. send data to server.( not yet recv data ).

    3. recv data from server.

    Now I worry that received data is mixed from server.

    • expected : "ABCD" "ABCD"

    • wrong: "AABBCDCD"

Question

I know that async_write function is guaranteed to be in order.

Thus, are the contents of the packets mixed?

Update:

Is this right?

async_read_some(MY::read1);

MY::read1() {
    async_write(someData, MY::write1);  // someData : "ABCD"
}

MY::write1() {
    async_read_some(MY::read1);
}
sehe
  • 374,641
  • 47
  • 450
  • 633
geeeek
  • 375
  • 2
  • 13
  • You need to wait for the handler to be called before you call write async again. Eg. you are not supposed to do two write async in a row before the first one completes. Same with read. But you can do both read and write at the same time. – Andrei Damian May 21 '18 at 08:09
  • I am not understand your comment well. I added psuedo code. It must write above skeleton? Could you write example about wrong/right asio code? – geeeek May 21 '18 at 08:29
  • 1
    See https://stackoverflow.com/questions/12794107/why-do-i-need-strand-per-connection-when-using-boostasio/12801042#12801042 – sehe May 21 '18 at 19:45

0 Answers0