#ifndef CONNECTION_HPP #define CONNECTION_HPP #include "server/http/compression_type.hpp" #include "server/http/reply.hpp" #include "server/http/request.hpp" #include "server/request_parser.hpp" #include #include #include #include #include #include // workaround for incomplete std::shared_ptr compatibility in old boost versions #if BOOST_VERSION < 105300 || defined BOOST_NO_CXX11_SMART_PTR namespace boost { template const T *get_pointer(std::shared_ptr const &p) { return p.get(); } template T *get_pointer(std::shared_ptr &p) { return p.get(); } } // namespace boost #endif namespace osrm { namespace server { class RequestHandler; /// Represents a single connection from a client. class Connection : public std::enable_shared_from_this { public: explicit Connection(boost::asio::io_service &io_service, RequestHandler &handler); Connection(const Connection &) = delete; Connection &operator=(const Connection &) = delete; boost::asio::ip::tcp::socket &socket(); /// Start the first asynchronous operation for the connection. void start(); private: void handle_read(const boost::system::error_code &e, std::size_t bytes_transferred); /// Handle completion of a write operation. void handle_write(const boost::system::error_code &e); /// Handle read timeout void handle_timeout(boost::system::error_code); void handle_shutdown(); std::vector compress_buffers(const std::vector &uncompressed_data, const http::compression_type compression_type); boost::asio::io_service::strand strand; boost::asio::ip::tcp::socket TCP_socket; boost::asio::deadline_timer timer; RequestHandler &request_handler; RequestParser request_parser; boost::array incoming_data_buffer; http::request current_request; http::reply current_reply; std::vector compressed_output; // Header compression_header; std::vector output_buffer; // Keep alive support bool keep_alive = false; short processed_requests = 512; short keepalive_timeout = 5; // In seconds }; } } #endif // CONNECTION_HPP