93 lines
2.7 KiB
C++
93 lines
2.7 KiB
C++
/*
|
|
|
|
Copyright (c) 2013, Project OSRM, Dennis Luxen, others
|
|
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.
|
|
|
|
*/
|
|
|
|
#ifndef CONNECTION_H
|
|
#define CONNECTION_H
|
|
|
|
#include "Http/CompressionType.h"
|
|
#include "Http/Request.h"
|
|
|
|
#include <osrm/Reply.h>
|
|
|
|
#include <boost/array.hpp>
|
|
#include <boost/asio.hpp>
|
|
#include <boost/enable_shared_from_this.hpp>
|
|
#include <boost/noncopyable.hpp>
|
|
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
class RequestHandler;
|
|
|
|
namespace http {
|
|
|
|
class RequestParser;
|
|
|
|
/// Represents a single connection from a client.
|
|
class Connection : public boost::enable_shared_from_this<Connection>,
|
|
private boost::noncopyable {
|
|
public:
|
|
explicit Connection(
|
|
boost::asio::io_service& io_service,
|
|
RequestHandler& handler
|
|
);
|
|
|
|
~Connection();
|
|
|
|
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);
|
|
|
|
void compressBufferCollection(
|
|
std::vector<std::string> uncompressed_data,
|
|
CompressionType compression_type,
|
|
std::vector<char> & compressed_data
|
|
);
|
|
|
|
boost::asio::io_service::strand strand;
|
|
boost::asio::ip::tcp::socket TCP_socket;
|
|
RequestHandler& request_handler;
|
|
boost::array<char, 8192> incoming_data_buffer;
|
|
Request request;
|
|
RequestParser * request_parser;
|
|
Reply reply;
|
|
};
|
|
|
|
} // namespace http
|
|
|
|
#endif // CONNECTION_H
|