2011-01-09 16:42:27 -05:00
|
|
|
/*
|
2013-10-14 07:42:28 -04:00
|
|
|
|
2015-01-26 07:35:24 -05:00
|
|
|
Copyright (c) 2015, Project OSRM, Dennis Luxen, others
|
2013-10-14 07:42:28 -04:00
|
|
|
All rights reserved.
|
|
|
|
|
|
|
|
Redistribution and use in source and binary forms, with or without modification,
|
|
|
|
are permitted provided that the following conditions are met:
|
|
|
|
|
|
|
|
Redistributions of source code must retain the above copyright notice, this list
|
|
|
|
of conditions and the following disclaimer.
|
|
|
|
Redistributions in binary form must reproduce the above copyright notice, this
|
|
|
|
list of conditions and the following disclaimer in the documentation and/or
|
|
|
|
other materials provided with the distribution.
|
|
|
|
|
|
|
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
|
|
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
|
|
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
|
|
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
|
|
|
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
|
|
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
|
|
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
|
|
|
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
|
|
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
|
|
|
*/
|
2011-01-09 16:42:27 -05:00
|
|
|
|
|
|
|
#ifndef CONNECTION_H
|
|
|
|
#define CONNECTION_H
|
|
|
|
|
2013-11-14 12:42:33 -05:00
|
|
|
#include "Http/CompressionType.h"
|
2014-11-24 11:57:01 -05:00
|
|
|
#include "Http/Reply.h"
|
2013-12-16 05:29:38 -05:00
|
|
|
#include "Http/Request.h"
|
2011-01-09 16:42:27 -05:00
|
|
|
|
2015-01-26 11:37:37 -05:00
|
|
|
#include <boost/array.hpp>
|
2013-09-19 05:54:24 -04:00
|
|
|
#include <boost/asio.hpp>
|
2014-05-11 10:51:14 -04:00
|
|
|
#include <boost/config.hpp>
|
|
|
|
#include <boost/version.hpp>
|
|
|
|
|
2015-01-23 12:53:37 -05:00
|
|
|
#include <memory>
|
|
|
|
#include <vector>
|
2014-05-11 10:51:14 -04:00
|
|
|
|
2015-01-23 12:53:37 -05:00
|
|
|
// workaround for incomplete std::shared_ptr compatibility in old boost versions
|
2014-05-11 10:51:14 -04:00
|
|
|
#if BOOST_VERSION < 105300 || defined BOOST_NO_CXX11_SMART_PTR
|
|
|
|
|
2015-01-23 12:53:37 -05:00
|
|
|
namespace boost
|
2014-05-11 10:51:14 -04:00
|
|
|
{
|
2015-01-23 12:53:37 -05:00
|
|
|
template <class T> const T *get_pointer(std::shared_ptr<T> const &p) { return p.get(); }
|
2014-05-11 10:51:14 -04:00
|
|
|
|
2015-01-23 12:53:37 -05:00
|
|
|
template <class T> T *get_pointer(std::shared_ptr<T> &p) { return p.get(); }
|
2014-05-11 10:51:14 -04:00
|
|
|
} // namespace boost
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2013-12-16 05:29:38 -05:00
|
|
|
class RequestHandler;
|
|
|
|
|
2014-05-07 11:08:30 -04:00
|
|
|
namespace http
|
|
|
|
{
|
2011-01-09 16:42:27 -05:00
|
|
|
|
|
|
|
/// Represents a single connection from a client.
|
2014-05-09 11:04:55 -04:00
|
|
|
class Connection : public std::enable_shared_from_this<Connection>
|
2014-05-07 11:06:28 -04:00
|
|
|
{
|
2014-05-07 11:08:30 -04:00
|
|
|
public:
|
|
|
|
explicit Connection(boost::asio::io_service &io_service, RequestHandler &handler);
|
|
|
|
Connection(const Connection &) = delete;
|
2014-06-12 07:46:07 -04:00
|
|
|
Connection() = delete;
|
2014-05-07 11:08:30 -04:00
|
|
|
|
|
|
|
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);
|
|
|
|
|
2015-01-26 07:35:24 -05:00
|
|
|
std::vector<char> compress_buffers(const std::vector<char> &uncompressed_data,
|
|
|
|
const CompressionType compression_type);
|
2014-05-07 11:08:30 -04:00
|
|
|
|
|
|
|
boost::asio::io_service::strand strand;
|
|
|
|
boost::asio::ip::tcp::socket TCP_socket;
|
|
|
|
RequestHandler &request_handler;
|
2015-01-26 11:37:37 -05:00
|
|
|
boost::array<char, 8192> incoming_data_buffer;
|
2014-05-07 11:08:30 -04:00
|
|
|
Request request;
|
|
|
|
Reply reply;
|
2011-01-09 16:42:27 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace http
|
|
|
|
|
|
|
|
#endif // CONNECTION_H
|