mirror of
https://github.com/pocoproject/poco.git
synced 2025-10-20 05:49:04 +02:00
ported 1.4.4 branch changes (needs build checks and test runs!)
This commit is contained in:
@@ -43,6 +43,7 @@
|
||||
#include "Poco/Net/NetException.h"
|
||||
#include "Poco/NumberFormatter.h"
|
||||
#include "Poco/Timestamp.h"
|
||||
#include "Poco/Delegate.h"
|
||||
#include <memory>
|
||||
|
||||
|
||||
@@ -53,14 +54,18 @@ namespace Net {
|
||||
HTTPServerConnection::HTTPServerConnection(const StreamSocket& socket, HTTPServerParams::Ptr pParams, HTTPRequestHandlerFactory::Ptr pFactory):
|
||||
TCPServerConnection(socket),
|
||||
_pParams(pParams),
|
||||
_pFactory(pFactory)
|
||||
_pFactory(pFactory),
|
||||
_stopped(false)
|
||||
{
|
||||
poco_check_ptr (pFactory);
|
||||
|
||||
_pFactory->serverStopped += Poco::delegate(this, &HTTPServerConnection::onServerStopped);
|
||||
}
|
||||
|
||||
|
||||
HTTPServerConnection::~HTTPServerConnection()
|
||||
{
|
||||
_pFactory->serverStopped -= Poco::delegate(this, &HTTPServerConnection::onServerStopped);
|
||||
}
|
||||
|
||||
|
||||
@@ -68,10 +73,12 @@ void HTTPServerConnection::run()
|
||||
{
|
||||
std::string server = _pParams->getSoftwareVersion();
|
||||
HTTPServerSession session(socket(), _pParams);
|
||||
while (session.hasMoreRequests())
|
||||
while (!_stopped && session.hasMoreRequests())
|
||||
{
|
||||
try
|
||||
{
|
||||
Poco::FastMutex::ScopedLock lock(_mutex);
|
||||
|
||||
HTTPServerResponseImpl response(session);
|
||||
HTTPServerRequestImpl request(response, session, _pParams);
|
||||
|
||||
@@ -124,4 +131,32 @@ void HTTPServerConnection::sendErrorResponse(HTTPServerSession& session, HTTPRes
|
||||
}
|
||||
|
||||
|
||||
void HTTPServerConnection::onServerStopped(const bool& abortCurrent)
|
||||
{
|
||||
_stopped = true;
|
||||
if (abortCurrent)
|
||||
{
|
||||
try
|
||||
{
|
||||
socket().shutdown();
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Poco::FastMutex::ScopedLock lock(_mutex);
|
||||
|
||||
try
|
||||
{
|
||||
socket().shutdown();
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
} } // namespace Poco::Net
|
||||
|
Reference in New Issue
Block a user