Boost logo

Boost :

Subject: [boost] asio loopback behavior, windows vs. linux
From: Adam Crain (jadamcrain_at_[hidden])
Date: 2010-06-07 17:51:26

There’s an interesting behavioral difference between how the loopback works
with ASIO on windows/linux.

I have constructed a test that talks to an echo server across the loopback.

The test steps are:

1) Open the socket using run_one(), verifying it is open

2) Start an async read

3) Start an async write

4) Call run_one, then verify the write succeeds

5) Call run_one, then verify that the data you write is received

6) Goto step 2 some number of times since the behavior is

One windows, this seems to consistently fail within the first 100
iterations, because on occasional you get the read callback with echoed data
before the write success comes back!!!!

This seems crazy that another process answers you before the OS/ASIO has
even told you the write was successful. On Linux I have not been able to
make this happen even with 10K’s of iterations.

I can only assume that:

1) This can actually happen with Windows loopback + thread scheduling
and my assumption that write callbacks will always occur before response
data is invalid

2) There is a bug in the windows impl of ASIO that makes this possible.

If anyone can shed some light on this I’d really appreciate it. I have code
that wants to step through a series of states, and it makes things a lot
more complicated if I can’t assume that the write callback will always occur
before data received that’s a response to what I sent.



Adam Crain

Manager of R&D

Green Energy Corp.


Boost list run by bdawes at, gregod at, cpdaniel at, john at