Boost C++ Libraries: Ticket #7392: boost::asio::ip::tcp::socket::is_open returns true even if socket is unusable https://svn.boost.org/trac10/ticket/7392 <p> socket.connect() failed with error code 10060: </p> <p> "A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond". </p> <p> Subsequent call to socket::is_open() method returns true (which is bad). Subsequent call to boost::asio::write(socket, ...) returns error code 10057 ("A request to send or receive data was disallowed because the socket is not connected and (w hen sending on a datagram socket using a sendto call) no address was supplied") (which is OK). </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/7392 Trac 1.4.3 anonymous Sat, 27 Oct 2012 09:17:07 GMT <link>https://svn.boost.org/trac10/ticket/7392#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/7392#comment:1</guid> <description> <p> I also see that behaviour with boost 1.49.0.1 (stock Debian package), but in my case the error from the call to connect failed with error 111: Connection refused </p> <p> Subsequent call to is_open returns != 0 </p> <p> 1902561 [0x7ffff7fc3760] ERROR inverter.Shared_Comms_Inverter1 null - Error while connecting: (111) Connection refused 1902561 [0x7ffff7fc3760] DEBUG inverter.Shared_Comms_Inverter1 null - new state: CMD_DISCONNECTED 1902561 [0x7ffff4d3b700] DEBUG inverter.Shared_Comms_Inverter1.Comms_SharedConnection..Comms_TCP_ASIO null - Already connected </p> </description> <category>Ticket</category> </item> <item> <dc:creator>anonymous</dc:creator> <pubDate>Sat, 27 Oct 2012 09:54:59 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/7392#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/7392#comment:2</guid> <description> <p> Note: In reactive_socket_service_base.hpp <em> Determine whether the socket is open. </em></p> <blockquote> <p> bool is_open(const base_implementation_type&amp; impl) const { </p> <blockquote> <p> return impl.socket_ != invalid_socket; </p> </blockquote> <p> } </p> </blockquote> <p> impl.socket_ is "8" in my case </p> <p> The issue is also present in 1.50 (the latest one in debian) </p> </description> <category>Ticket</category> </item> <item> <dc:creator>anonymous</dc:creator> <pubDate>Sat, 27 Oct 2012 09:56:03 GMT</pubDate> <title>version changed https://svn.boost.org/trac10/ticket/7392#comment:3 https://svn.boost.org/trac10/ticket/7392#comment:3 <ul> <li><strong>version</strong> <span class="trac-field-old">Boost 1.51.0</span> → <span class="trac-field-new">Boost 1.49.0</span> </li> </ul> Ticket chris_kohlhoff Sat, 29 Dec 2012 10:03:07 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/7392#comment:4 https://svn.boost.org/trac10/ticket/7392#comment:4 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">invalid</span> </li> </ul> <p> A socket is not automatically closed when the connect fails, hence is_open still returns true. This is the intended (and documented) behaviour. You need to check the error code produced by the operation and act on it accordingly. </p> Ticket