Boost logo

Boost Users :

Subject: [Boost-users] Multiple async operations on a socket
From: Kyle Tarplee (Kyle.Tarplee_at_[hidden])
Date: 2009-09-16 10:41:43


I have a rather simple question that I can't find in the boost::asio
documentation.

I have a boost::asio::ip::tcp::socket that I want to write to. Can I
have multiple outstanding async_write() requests for a single socket?
Are the writes performed in the order in which they are submitted? Or
is this undefined behavior?

How about multiple async_read() requests on the same socket?

I know that I need to write to the socket from at most one thread but
that doesn't preclude me from not waiting until the first one is done
to put on the second async write or read.

The reason I ask is because there seems to be two ways to write data
to a socket.
1) The "fire and forget" approach (no queue, simply call async_write()
                 when you want to write and ignore the completion
handler callback)
2) Push on a queue when you want to write something. Pop from the
queue when the preceeding
                 async_write() operation completed. Thus at most one
async_write()
operation is
                 associated with the socket at any point in time.

Thanks in advance,
Kyle


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net