
1 Apr
2009
1 Apr
'09
7:21 a.m.
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.