mirror of
https://github.com/pocoproject/poco.git
synced 2025-10-26 18:42:41 +01:00
Peroperly use the maxThreads specified in a TCPServerParameters to have the TCPServerDispatcher create a Threadpool with the correct capacity.
This commit is contained in:
@@ -162,6 +162,9 @@ public:
|
||||
int currentThreads() const;
|
||||
/// Returns the number of currently used connection threads.
|
||||
|
||||
int maxThreads() const;
|
||||
/// Returns the maximum number of threads available.
|
||||
|
||||
int totalConnections() const;
|
||||
/// Returns the total number of handled connections.
|
||||
|
||||
|
||||
@@ -86,6 +86,9 @@ public:
|
||||
int currentThreads() const;
|
||||
/// Returns the number of currently used threads.
|
||||
|
||||
int maxThreads() const;
|
||||
/// Returns the maximum number of threads available.
|
||||
|
||||
int totalConnections() const;
|
||||
/// Returns the total number of handled connections.
|
||||
|
||||
|
||||
@@ -52,19 +52,29 @@ namespace Net {
|
||||
|
||||
TCPServer::TCPServer(TCPServerConnectionFactory::Ptr pFactory, Poco::UInt16 portNumber, TCPServerParams::Ptr pParams):
|
||||
_socket(ServerSocket(portNumber)),
|
||||
_pDispatcher(new TCPServerDispatcher(pFactory, Poco::ThreadPool::defaultPool(), pParams)),
|
||||
_thread(threadName(_socket)),
|
||||
_stopped(true)
|
||||
{
|
||||
|
||||
Poco::ThreadPool& pool = Poco::ThreadPool::defaultPool();
|
||||
if(pParams && (pParams->getMaxThreads() > pool.capacity())){
|
||||
pool.addCapacity(pParams->getMaxThreads());
|
||||
}
|
||||
_pDispatcher = new TCPServerDispatcher(pFactory, pool, pParams);
|
||||
|
||||
}
|
||||
|
||||
|
||||
TCPServer::TCPServer(TCPServerConnectionFactory::Ptr pFactory, const ServerSocket& socket, TCPServerParams::Ptr pParams):
|
||||
_socket(socket),
|
||||
_pDispatcher(new TCPServerDispatcher(pFactory, Poco::ThreadPool::defaultPool(), pParams)),
|
||||
_thread(threadName(socket)),
|
||||
_stopped(true)
|
||||
{
|
||||
Poco::ThreadPool& pool = Poco::ThreadPool::defaultPool();
|
||||
if(pParams && (pParams->getMaxThreads() > pool.capacity())){
|
||||
pool.addCapacity(pParams->getMaxThreads());
|
||||
}
|
||||
_pDispatcher = new TCPServerDispatcher(pFactory, pool, pParams);
|
||||
}
|
||||
|
||||
|
||||
@@ -146,6 +156,11 @@ int TCPServer::currentThreads() const
|
||||
return _pDispatcher->currentThreads();
|
||||
}
|
||||
|
||||
int TCPServer::maxThreads() const
|
||||
{
|
||||
return _pDispatcher->maxThreads();
|
||||
}
|
||||
|
||||
|
||||
int TCPServer::totalConnections() const
|
||||
{
|
||||
|
||||
@@ -197,6 +197,13 @@ int TCPServerDispatcher::currentThreads() const
|
||||
return _currentThreads;
|
||||
}
|
||||
|
||||
int TCPServerDispatcher::maxThreads() const
|
||||
{
|
||||
FastMutex::ScopedLock lock(_mutex);
|
||||
|
||||
return _threadPool.capacity();
|
||||
}
|
||||
|
||||
|
||||
int TCPServerDispatcher::totalConnections() const
|
||||
{
|
||||
|
||||
@@ -175,6 +175,7 @@ void TCPServerTest::testMultiConnections()
|
||||
srv.start();
|
||||
assert (srv.currentConnections() == 0);
|
||||
assert (srv.currentThreads() == 0);
|
||||
assert (srv.maxThreads() >= 4);
|
||||
assert (srv.queuedConnections() == 0);
|
||||
assert (srv.totalConnections() == 0);
|
||||
|
||||
@@ -252,6 +253,16 @@ void TCPServerTest::testMultiConnections()
|
||||
assert (srv.currentConnections() == 0);
|
||||
}
|
||||
|
||||
void TCPServerTest::testThreadCapacity(){
|
||||
ServerSocket svs(0);
|
||||
TCPServerParams* pParams = new TCPServerParams;
|
||||
pParams->setMaxThreads(64);
|
||||
TCPServer srv(new TCPServerConnectionFactoryImpl<EchoConnection>(), svs, pParams);
|
||||
srv.start();
|
||||
assert (srv.maxThreads() >= 64);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void TCPServerTest::setUp()
|
||||
{
|
||||
@@ -270,6 +281,7 @@ CppUnit::Test* TCPServerTest::suite()
|
||||
CppUnit_addTest(pSuite, TCPServerTest, testOneConnection);
|
||||
CppUnit_addTest(pSuite, TCPServerTest, testTwoConnections);
|
||||
CppUnit_addTest(pSuite, TCPServerTest, testMultiConnections);
|
||||
CppUnit_addTest(pSuite, TCPServerTest, testThreadCapacity);
|
||||
|
||||
return pSuite;
|
||||
}
|
||||
|
||||
@@ -49,6 +49,7 @@ public:
|
||||
void testOneConnection();
|
||||
void testTwoConnections();
|
||||
void testMultiConnections();
|
||||
void testThreadCapacity();
|
||||
|
||||
void setUp();
|
||||
void tearDown();
|
||||
|
||||
Reference in New Issue
Block a user