|
Boost Users : |
Subject: Re: [Boost-users] stop thread before socket destructor
From: Gianni Ambrosio (gianni.ambrosio_at_[hidden])
Date: 2011-04-28 05:11:45
Il 4/28/2011 12:21 AM, Igor R ha scritto:
>> Now, how could I stop the thread in the server destructor so that the handle_accept is not called anymore?
> You can wait until io_service::run() exits:
>
>> ~stream_handler()
>> {
>> acceptor_.close();
>
> //...
> thread_.join();
> }
I think that would not prevent the handle_accept to be called after the
server destructor, with an error code related to the message I told you
in the previous email.
I find a solution in a different way, using the
boost::asio::io_service::work.
I added a member variable:
boost::asio::io_service::work work_;
I instanciated it in the server constructor as follows:
work_(io_service_)
Then in the server destructor:
~stream_handler()
{
io_service_.stop();
}
That seems working and the handle_accept is never called after the
destructor.
Thanks,
Gianni
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net