ported 1.4.4 branch changes (needs build checks and test runs!)

This commit is contained in:
Aleksandar Fabijanic
2012-05-19 03:04:51 +00:00
parent e5e3a57baf
commit 9b952a29c7
62 changed files with 1361 additions and 135 deletions

View File

@@ -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