diff --git a/Net/include/Poco/Net/TCPServerDispatcher.h b/Net/include/Poco/Net/TCPServerDispatcher.h index 8070b2973..9965e1ace 100644 --- a/Net/include/Poco/Net/TCPServerDispatcher.h +++ b/Net/include/Poco/Net/TCPServerDispatcher.h @@ -101,30 +101,6 @@ private: TCPServerDispatcher(const TCPServerDispatcher&); TCPServerDispatcher& operator = (const TCPServerDispatcher&); - class ThreadCountWatcher - { - public: - ThreadCountWatcher(TCPServerDispatcher* pDisp) : _pDisp(pDisp) - { - } - - ~ThreadCountWatcher() - { - FastMutex::ScopedLock lock(_pDisp->_mutex); - if (_pDisp->_currentThreads > 1 && _pDisp->_queue.empty()) - { - --_pDisp->_currentThreads; - } - } - - private: - ThreadCountWatcher(); - ThreadCountWatcher(const ThreadCountWatcher&); - ThreadCountWatcher& operator=(const ThreadCountWatcher&); - - TCPServerDispatcher* _pDisp; - }; - std::atomic _rc; TCPServerParams::Ptr _pParams; std::atomic _currentThreads; diff --git a/Net/src/TCPServerDispatcher.cpp b/Net/src/TCPServerDispatcher.cpp index efb8b2a31..2d974ae93 100644 --- a/Net/src/TCPServerDispatcher.cpp +++ b/Net/src/TCPServerDispatcher.cpp @@ -103,29 +103,31 @@ void TCPServerDispatcher::run() for (;;) { + try { - ThreadCountWatcher tcw(this); - try + AutoPtr pNf = _queue.waitDequeueNotification(idleTime); + if (pNf) { - AutoPtr pNf = _queue.waitDequeueNotification(idleTime); - if (pNf) + TCPConnectionNotification* pCNf = dynamic_cast(pNf.get()); + if (pCNf) { - TCPConnectionNotification* pCNf = dynamic_cast(pNf.get()); - if (pCNf) - { - std::unique_ptr pConnection(_pConnectionFactory->createConnection(pCNf->socket())); - poco_check_ptr(pConnection.get()); - beginConnection(); - pConnection->start(); - endConnection(); - } + std::unique_ptr pConnection(_pConnectionFactory->createConnection(pCNf->socket())); + poco_check_ptr(pConnection.get()); + beginConnection(); + pConnection->start(); + endConnection(); } } - catch (Poco::Exception &exc) { ErrorHandler::handle(exc); } - catch (std::exception &exc) { ErrorHandler::handle(exc); } - catch (...) { ErrorHandler::handle(); } } - if (_stopped || (_currentThreads > 1 && _queue.empty())) break; + catch (Poco::Exception &exc) { ErrorHandler::handle(exc); } + catch (std::exception &exc) { ErrorHandler::handle(exc); } + catch (...) { ErrorHandler::handle(); } + FastMutex::ScopedLock lock(_mutex); + if (_stopped || (_currentThreads > 1 && _queue.empty())) + { + --_currentThreads; + break; + } } }