Receive timeout should only be active for a second and
following requests on a keep-alive connections.
This commit is contained in:
parent
4fbf58adb3
commit
9efcab2108
@ -53,7 +53,9 @@ class Connection : public std::enable_shared_from_this<Connection>
|
|||||||
void handle_write(const boost::system::error_code &e);
|
void handle_write(const boost::system::error_code &e);
|
||||||
|
|
||||||
/// Handle read timeout
|
/// Handle read timeout
|
||||||
void handle_timeout();
|
void handle_timeout(boost::system::error_code);
|
||||||
|
|
||||||
|
void handle_shutdown();
|
||||||
|
|
||||||
std::vector<char> compress_buffers(const std::vector<char> &uncompressed_data,
|
std::vector<char> compress_buffers(const std::vector<char> &uncompressed_data,
|
||||||
const http::compression_type compression_type);
|
const http::compression_type compression_type);
|
||||||
|
@ -10,7 +10,6 @@
|
|||||||
|
|
||||||
#include <iterator>
|
#include <iterator>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <util/log.hpp>
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
namespace osrm
|
namespace osrm
|
||||||
@ -35,10 +34,14 @@ void Connection::start()
|
|||||||
boost::asio::placeholders::error,
|
boost::asio::placeholders::error,
|
||||||
boost::asio::placeholders::bytes_transferred)));
|
boost::asio::placeholders::bytes_transferred)));
|
||||||
|
|
||||||
// init async timer
|
if (keep_alive)
|
||||||
timer.cancel();
|
{
|
||||||
timer.expires_from_now(boost::posix_time::seconds(keepalive_timeout));
|
// Ok, we know it is not a first request, as we switched to keepalive
|
||||||
timer.async_wait(boost::bind(&Connection::handle_timeout, this->shared_from_this()));
|
timer.cancel();
|
||||||
|
timer.expires_from_now(boost::posix_time::seconds(keepalive_timeout));
|
||||||
|
timer.async_wait(std::bind(
|
||||||
|
&Connection::handle_timeout, this->shared_from_this(), std::placeholders::_1));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Connection::handle_read(const boost::system::error_code &error, std::size_t bytes_transferred)
|
void Connection::handle_read(const boost::system::error_code &error, std::size_t bytes_transferred)
|
||||||
@ -48,6 +51,12 @@ void Connection::handle_read(const boost::system::error_code &error, std::size_t
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (keep_alive)
|
||||||
|
{
|
||||||
|
timer.cancel();
|
||||||
|
timer.expires_from_now(boost::posix_time::seconds(0));
|
||||||
|
}
|
||||||
|
|
||||||
// no error detected, let's parse the request
|
// no error detected, let's parse the request
|
||||||
http::compression_type compression_type(http::no_compression);
|
http::compression_type compression_type(http::no_compression);
|
||||||
RequestParser::RequestStatus result;
|
RequestParser::RequestStatus result;
|
||||||
@ -143,15 +152,27 @@ void Connection::handle_write(const boost::system::error_code &error)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Initiate graceful connection closure.
|
handle_shutdown();
|
||||||
handle_timeout();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Handle completion of a write operation.
|
/// Handle completion of a timeout timer..
|
||||||
void Connection::handle_timeout()
|
void Connection::handle_timeout(boost::system::error_code ec)
|
||||||
{
|
{
|
||||||
|
// We can get there for 3 reasons: spurious wakeup by timer.cancel(), which should be ignored
|
||||||
|
// Slow client with a delayed _first_ request, which should be ignored too
|
||||||
|
// Absent next request during waiting time in the keepalive mode - should stop right there.
|
||||||
|
if (ec != boost::asio::error::operation_aborted)
|
||||||
|
{
|
||||||
|
TCP_socket.cancel();
|
||||||
|
handle_shutdown();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Connection::handle_shutdown()
|
||||||
|
{
|
||||||
|
// Initiate graceful connection closure.
|
||||||
boost::system::error_code ignore_error;
|
boost::system::error_code ignore_error;
|
||||||
TCP_socket.shutdown(boost::asio::ip::tcp::socket::shutdown_both, ignore_error);
|
TCP_socket.shutdown(boost::asio::ip::tcp::socket::shutdown_both, ignore_error);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user