Boost logo

Boost Users :

Subject: Re: [Boost-users] tcp::socket::is_open() is true after socket is closed
From: Gavin Lambert (gavinl_at_[hidden])
Date: 2013-09-19 23:45:39

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.)

Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at