From 6a7d1e57c7f1f92c5178182943d3409b0413b104 Mon Sep 17 00:00:00 2001 From: Jan Steemann Date: Mon, 15 Oct 2012 21:34:28 +0200 Subject: [PATCH] issue #231: set request timeout for requests that come in incomplete --- lib/HttpServer/HttpCommTask.h | 9 +++++++++ lib/Scheduler/SocketTask.cpp | 30 ++++++++++++++++++++++++++---- lib/Scheduler/SocketTask.h | 21 +++++++++++++++++++++ 3 files changed, 56 insertions(+), 4 deletions(-) diff --git a/lib/HttpServer/HttpCommTask.h b/lib/HttpServer/HttpCommTask.h index 385468bfac..1b37b4fe9e 100644 --- a/lib/HttpServer/HttpCommTask.h +++ b/lib/HttpServer/HttpCommTask.h @@ -278,6 +278,15 @@ namespace triagens { if (this->_readBuffer->length() - this->_bodyPosition < this->_bodyLength) { // still more data to be read + + SocketTask* socketTask = dynamic_cast(this); + if (socketTask) { + // set read request time-out + LOGGER_TRACE << "waiting for rest of body to be received. request timeout set to 60 s"; + socketTask->setKeepAliveTimeout(60.0); + } + + // let client send more return true; } diff --git a/lib/Scheduler/SocketTask.cpp b/lib/Scheduler/SocketTask.cpp index 704307c352..9f149f2073 100644 --- a/lib/Scheduler/SocketTask.cpp +++ b/lib/Scheduler/SocketTask.cpp @@ -110,6 +110,29 @@ SocketTask::~SocketTask () { /// @} //////////////////////////////////////////////////////////////////////////////// +// ----------------------------------------------------------------------------- +// --SECTION-- public methods +// ----------------------------------------------------------------------------- + +//////////////////////////////////////////////////////////////////////////////// +/// @addtogroup Scheduler +/// @{ +//////////////////////////////////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////////////////////////// +/// {@inheritDoc} +//////////////////////////////////////////////////////////////////////////////// + +void SocketTask::setKeepAliveTimeout (double timeout) { + if (keepAliveWatcher != 0 && timeout > 0.0) { + scheduler->rearmTimer(keepAliveWatcher, timeout); + } +} + +//////////////////////////////////////////////////////////////////////////////// +/// @} +//////////////////////////////////////////////////////////////////////////////// + // ----------------------------------------------------------------------------- // --SECTION-- protected virtual methods // ----------------------------------------------------------------------------- @@ -221,10 +244,8 @@ bool SocketTask::handleWrite (bool& closed, bool noWrite) { } // rearm timer for keep-alive timeout - if (_keepAliveTimeout > 0.0) { - // TODO: do we need some lock before we modify the scheduler? - scheduler->rearmTimer(keepAliveWatcher, _keepAliveTimeout); - } + // TODO: do we need some lock before we modify the scheduler? + setKeepAliveTimeout(_keepAliveTimeout); } // we might have a new write buffer or none at all @@ -444,6 +465,7 @@ bool SocketTask::handleEvent (EventToken token, EventType revents) { // disable timer for keep-alive timeout scheduler->clearTimer(keepAliveWatcher); } + result = handleRead(closed); } diff --git a/lib/Scheduler/SocketTask.h b/lib/Scheduler/SocketTask.h index b8c96e69ae..f6db8a1b9e 100644 --- a/lib/Scheduler/SocketTask.h +++ b/lib/Scheduler/SocketTask.h @@ -104,6 +104,27 @@ namespace triagens { /// @} //////////////////////////////////////////////////////////////////////////////// +// ----------------------------------------------------------------------------- +// --SECTION-- public methods +// ----------------------------------------------------------------------------- + +//////////////////////////////////////////////////////////////////////////////// +/// @addtogroup Scheduler +/// @{ +//////////////////////////////////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////////////////////////// +/// set a request timeout +//////////////////////////////////////////////////////////////////////////////// + + public: + + void setKeepAliveTimeout (double); + +//////////////////////////////////////////////////////////////////////////////// +/// @} +//////////////////////////////////////////////////////////////////////////////// + // ----------------------------------------------------------------------------- // --SECTION-- protected virtual methods // -----------------------------------------------------------------------------