Commit 5049b428 authored by Michal Vaner's avatar Michal Vaner

Better way to stop io_service from running out of work

Instead of detecting when it stopped, use dummy work object to keep it
busy.

git-svn-id: svn://bind10.isc.org/svn/bind10/branches/vorner-recursor-config@3422 e5f2f494-b856-4b98-b285-d166d9295462
parent 9d2c2106
......@@ -52,6 +52,8 @@ public:
SimpleCallback* checkin, DNSLookup* lookup,
DNSAnswer* answer);
asio::io_service io_service_;
// So it does not run out of work when there are no listening sockets
asio::io_service::work work_;
typedef boost::shared_ptr<UDPServer> UDPServerPtr;
typedef boost::shared_ptr<TCPServer> TCPServerPtr;
......@@ -107,6 +109,7 @@ IOServiceImpl::IOServiceImpl(const char& port,
SimpleCallback* checkin,
DNSLookup* lookup,
DNSAnswer* answer) :
work_(io_service_),
checkin_(checkin),
lookup_(lookup),
answer_(answer)
......@@ -187,21 +190,12 @@ IOService::clearServers() {
void
IOService::run() {
if (!impl_->io_service_.run()) {
// We got the io_service in stopped state and it didn't work
// Reset it and try again
impl_->io_service_.reset();
impl_->io_service_.run();
}
impl_->io_service_.run();
}
void
IOService::run_one() {
if (!impl_->io_service_.run_one()) {
// Same as in run() - we got it in stopped state
impl_->io_service_.reset();
impl_->io_service_.run_one();
}
impl_->io_service_.run_one();
}
void
......
......@@ -182,12 +182,7 @@ SessionImpl::readData(void* data, size_t datalen) {
// When one of them has a result, cancel the other, and wait
// until the cancel is processed before we continue
while (!read_result && !timer_result) {
if (!socket_.io_service().run_one()) {
// We run out of work last time we did readData
// and there seems to be no way to test if it is running.
// We know when it returns 0, it is stopped.
socket_.io_service().reset();
}
socket_.io_service().run_one();
// Don't cancel the timer if we haven't set it
if (read_result && getTimeout() != 0) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment