Socket iostream Question

Hello all,
I am developing a high-performance socket-based application using the
boost asio library. The application implements a binary tcp-based protocol
that a bi-directional exchange of fixed-size messages. To simplify the
coding while not sacrificing flexibility or performance, I decided to use
the TCP iostream classes. The approach seems to work well, and I like the
fact that the streams are buffered and allow me control over when I flush
them. There's one minor issue that I thought I would seek some guidance on:
Diagnosing and reporting failures connecting to servers are problematic.
Basically, if a connect fails, the only way to know about it is to check the
fail bit of the iostream. It would be nice to know why a client is unable to
connect. So, to that end, I thought I could construct the iostream object
via the default constructor, grab its streambuf via the rdbuf() call and in
turn grab a basic_socket object reference to the streambuf and then call
connect() on it, i.e.,
tcp::iostream iStream ;
boost::asio::basic_socket_streambuf<tcp>& buf(*(iStream.rdbuf()));
boost::asio::basic_socket

Diagnosing and reporting failures connecting to servers are problematic. Basically, if a connect fails, the only way to know about it is to check the fail bit of the iostream. It would be nice to know why a client is unable to connect. So, to that end, I thought I could construct the iostream object via the default constructor, grab its streambuf via the rdbuf() call and in turn grab a basic_socket object reference to the streambuf and then call connect() on it, i.e.,
Wouldn't it be easier to extract the fileno from the stream and query the error with getsockopt ? With this approach you could stay fully asynchronous yet get the real error code if a connection attempt fails.
participants (2)
-
Anthrope
-
Rudolf Leitgeb