Boost logo

Boost Users :

From: Rod Morison (rod_at_[hidden])
Date: 2006-09-07 20:07:17


Is there way to query the local status of a socket in asio? Or, is
there another technique for state & error management?

For example, something lick the TcpSocket state in Qt v4. I.e.,

AbstractSocket::UnconnectedState 0 The socket is not connected.
QAbstractSocket::HostLookupState 1 The socket is performing a
host name lookup.
QAbstractSocket::ConnectingState 2 The socket has started
establishing a connection.
QAbstractSocket::ConnectedState 3 A connection is established.
QAbstractSocket::BoundState 4 The socket is bound to an address
and port (for servers).
QAbstractSocket::ClosingState 6 The socket is about to close
(data may still be waiting to be written).
QAbstractSocket::ListeningState 5 For internal use only.

(from http://doc.trolltech.com/4.2/qabstractsocket.html#SocketState-enum)

Here's why I'm asking: I'm looking at the chat_client.cpp example.The
socket is connected via async_connect in the chat_client constructor.
If the first resolved endpoint fails to connect the handler tries an
async_connect with the next endpoint.

First question: Are the async requests initiated under an io_servce
(and executed by the run() method) queued in the order they are called
via async_xxx calls? (I'm assuming/hoping that's a yes.)

So the issue I have with the chat_client design is as follows: because
iterating the endpoint list (to connect the socket) is in a handler,
what if another socket operation slipped in ahead of that handler, say
a write (assuming the first endpoint failed)? I'd want the do_write()
function to be able to check the socket state. I can do the state
control myself via the handlers and a class state variable, but is
there a better way? (Similarly, this app can happily go writing to an
unconnected socket--I realize it's a sample, not production code, but
I'm thinking through my _real_ app here.)

Hope this makes sense,

Rod


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