Formatted the code.

This commit is contained in:
Denis Chaplygin 2019-08-19 16:27:45 +03:00
parent 22550d078f
commit a7b7d77e1f
2 changed files with 51 additions and 47 deletions

View File

@ -2,16 +2,16 @@
#include "server/request_handler.hpp" #include "server/request_handler.hpp"
#include "server/request_parser.hpp" #include "server/request_parser.hpp"
#include <boost/algorithm/string/predicate.hpp>
#include <boost/assert.hpp> #include <boost/assert.hpp>
#include <boost/bind.hpp> #include <boost/bind.hpp>
#include <boost/algorithm/string/predicate.hpp>
#include <boost/iostreams/filter/gzip.hpp> #include <boost/iostreams/filter/gzip.hpp>
#include <boost/iostreams/filtering_stream.hpp> #include <boost/iostreams/filtering_stream.hpp>
#include <iterator> #include <iterator>
#include <string> #include <string>
#include <vector>
#include <util/log.hpp> #include <util/log.hpp>
#include <vector>
namespace osrm namespace osrm
{ {
@ -38,9 +38,7 @@ void Connection::start()
// init async timer // init async timer
timer.cancel(); timer.cancel();
timer.expires_from_now(boost::posix_time::seconds(keepalive_timeout)); timer.expires_from_now(boost::posix_time::seconds(keepalive_timeout));
timer.async_wait(boost::bind(&Connection::handle_timeout, timer.async_wait(boost::bind(&Connection::handle_timeout, this->shared_from_this()));
this->shared_from_this()));
} }
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)
@ -64,9 +62,12 @@ void Connection::handle_read(const boost::system::error_code &error, std::size_t
current_request.endpoint = TCP_socket.remote_endpoint().address(); current_request.endpoint = TCP_socket.remote_endpoint().address();
request_handler.HandleRequest(current_request, current_reply); request_handler.HandleRequest(current_request, current_reply);
if (boost::iequals(current_request.connection, "close")) { if (boost::iequals(current_request.connection, "close"))
{
current_reply.headers.emplace_back("Connection", "close"); current_reply.headers.emplace_back("Connection", "close");
} else { }
else
{
keep_alive = true; keep_alive = true;
current_reply.headers.emplace_back("Connection", "keep-alive"); current_reply.headers.emplace_back("Connection", "keep-alive");
current_reply.headers.emplace_back("Keep-Alive", "timeout=5, max=512"); current_reply.headers.emplace_back("Keep-Alive", "timeout=5, max=512");
@ -133,12 +134,15 @@ void Connection::handle_write(const boost::system::error_code &error)
{ {
if (!error) if (!error)
{ {
if (keep_alive && processed_requests > 0) { if (keep_alive && processed_requests > 0)
{
--processed_requests; --processed_requests;
current_request = http::request(); current_request = http::request();
request_parser = RequestParser(); request_parser = RequestParser();
this->start(); this->start();
} else { }
else
{
// Initiate graceful connection closure. // Initiate graceful connection closure.
handle_timeout(); handle_timeout();
} }