tcp::socket::is_open() is true after socket is closed
Hi, In the following simple code: tcp::socket socket(ios); ... const bool iso1 = socket.is_open(); socket.close(); const bool iso2 = socket.is_open(); I get: iso1 == iso2 == true Why? Thanks. -- Regards, niXman ___________________________________________________ Dual-target(32 & 64-bit) MinGW compilers for 32 and 64-bit Windows: http://sourceforge.net/projects/mingwbuilds/ ___________________________________________________ Another online IDE: http://liveworkspace.org/
On 9/19/2013 12:32 AM, Quoth niXman:
tcp::socket socket(ios); ... const bool iso1 = socket.is_open(); socket.close(); const bool iso2 = socket.is_open();
I get: iso1 == iso2 == true
Why?
I don't know if this is true of tcp::socket or not, but I was recently implementing a custom ASIO-based io object that could not complete a close() synchronously unless it was being called from an I/O worker thread. So it would behave similarly to the above. The actual close will probably complete asynchronously in the background, as long as you have a thread still in io_service::run(). (Or, only if you can guarantee you have no such threads, or that you're ok with the multi-thread implications of it, you can call io_service::poll() after closing to get it to complete locally.)
participants (2)
-
Gavin Lambert
-
niXman