feed_.initModel();
// Start timer for detecting timeouts.
- timeout_timer_.setup(boost::bind(&Connection::timeoutHandler, this),
- timeout_ * 1000, IntervalTimer::ONE_SHOT);
+ scheduleTimer();
}
/// @brief Destructor.
timeout_timer_.cancel();
}
+ /// @brief This method schedules timer or reschedules existing timer.
+ void scheduleTimer() {
+ timeout_timer_.setup(boost::bind(&Connection::timeoutHandler, this),
+ timeout_ * 1000, IntervalTimer::ONE_SHOT);
+ }
+
/// @brief Close current connection.
///
/// Connection is not closed if the invocation of this method is a result of
LOG_DEBUG(command_logger, DBG_COMMAND, COMMAND_SOCKET_READ)
.arg(bytes_transferred).arg(socket_->getNative());
+ // Reschedule the timer because the transaction is ongoing.
+ scheduleTimer();
+
ConstElementPtr rsp;
try {
ConstElementPtr cmd = feed_.toElement();
response_in_progress_ = true;
+ // Cancel the timer to make sure that long lasting command
+ // processing doesn't cause the timeout.
+ timeout_timer_.cancel();
+
// If successful, then process it as a command.
rsp = CommandMgr::instance().processCommand(cmd);
} else {
+ // Reschedule the timer as it may be either canceled or need to be
+ // updated to not timeout before we manage to the send the reply.
+ scheduleTimer();
+
// Let's convert JSON response to text. Note that at this stage
// the rsp pointer is always set.
response_ = rsp->str();
}
} else {
+
+ // Reschedule the timer because the transaction is ongoing.
+ scheduleTimer();
+
// No error. We are in a process of sending a response. Need to
// remove the chunk that we have managed to sent with the previous
// attempt.