|
Boost Users : |
Subject: Re: [Boost-users] io_service run thread exits on network disconnect (chat server example)
From: Igor R (boost.lists_at_[hidden])
Date: 2010-02-26 04:06:37
> After network cable is unplugged, a call to GetAllWI does not call write_wis_for_oow_req. I can see an exit thread message in Visual Studio output window.
io_service::run() exits, if io_service has no more work. Eg., all your
read/write handlers have been called, and no new async. operation were
enqueued. You can use a "work" class to prevent io_service::run() from
exiting:
http://www.boost.org/doc/libs/1_42_0/doc/html/boost_asio/reference/io_service.html
> 1. It would be great help if someone can suggest a way to handle this scenario. Is there a way to know this io_service::run has exited.
You can call the run() method from your own function:
//....
void do_run(io_service *io)
{
io->run();
std::cout << "io_service::run ended" <<std::eol;
}
//...
thread t(&do_run, &io_service);
> My program needs to handle this scenario and Client should be able to detect network problem and reconnect.
Take a look at this thread:
http://old.nabble.com/-asio--Detecting-tcp-peer-disconnection-td27357792.html
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