diff --git a/Net/src/TCPServer.cpp b/Net/src/TCPServer.cpp index 1619ca0ef..aa7a8cf6d 100644 --- a/Net/src/TCPServer.cpp +++ b/Net/src/TCPServer.cpp @@ -115,28 +115,38 @@ void TCPServer::run() while (!_stopped) { Poco::Timespan timeout(250000); - if (_socket.poll(timeout, Socket::SELECT_READ)) + try { - try + if (_socket.poll(timeout, Socket::SELECT_READ)) { - StreamSocket ss = _socket.acceptConnection(); - // enabe nodelay per default: OSX really needs that - ss.setNoDelay(true); - _pDispatcher->enqueue(ss); - } - catch (Poco::Exception& exc) - { - ErrorHandler::handle(exc); - } - catch (std::exception& exc) - { - ErrorHandler::handle(exc); - } - catch (...) - { - ErrorHandler::handle(); + try + { + StreamSocket ss = _socket.acceptConnection(); + // enabe nodelay per default: OSX really needs that + ss.setNoDelay(true); + _pDispatcher->enqueue(ss); + } + catch (Poco::Exception& exc) + { + ErrorHandler::handle(exc); + } + catch (std::exception& exc) + { + ErrorHandler::handle(exc); + } + catch (...) + { + ErrorHandler::handle(); + } } } + catch (Poco::Exception& exc) + { + ErrorHandler::handle(exc); + // possibly a resource issue since poll() failed; + // give some time to recover before trying again + Poco::Thread::sleep(50); + } } } @@ -146,6 +156,7 @@ int TCPServer::currentThreads() const return _pDispatcher->currentThreads(); } + int TCPServer::maxThreads() const { return _pDispatcher->maxThreads();