Phew, a lot of classes were affected by this. The rationale for the changes are as follows: - When a type X declares any constructor, the default constructor is not declared, so there is no need for X() = delete there. In fact, there is brutal difference between those two: deleted members participate in overload resolution, but not-declared members do not! - When a type X wants to be non-copyable (e.g. to be only movable, like threads, unique_ptrs, and so on), you can either do it by inheriting from boost::noncopyable (the old way), or better declare both (!) the copy constructor _and_ the copy assignment operator as deleted: X(X const&) = delete; X& operator=(X const&) = delete; We had tons of types with deleted copy constructors that were lacking a corresponding deleted copy assignment operator, making them still copyable and you wouldn't even notice (read: scary)! References: - http://accu.org/content/conf2014/Howard_Hinnant_Accu_2014.pdf - http://www.boost.org/doc/libs/master/libs/core/doc/html/core/noncopyable.html Note: I know, I'm quoting Hinnant's extraordinary slides a lot, but getting the sematic right here is so incredibly important.
73 lines
2.0 KiB
C++
73 lines
2.0 KiB
C++
#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 <boost/array.hpp>
|
|
#include <boost/asio.hpp>
|
|
#include <boost/config.hpp>
|
|
#include <boost/version.hpp>
|
|
|
|
#include <memory>
|
|
#include <vector>
|
|
|
|
// workaround for incomplete std::shared_ptr compatibility in old boost versions
|
|
#if BOOST_VERSION < 105300 || defined BOOST_NO_CXX11_SMART_PTR
|
|
|
|
namespace boost
|
|
{
|
|
template <class T> const T *get_pointer(std::shared_ptr<T> const &p) { return p.get(); }
|
|
|
|
template <class T> T *get_pointer(std::shared_ptr<T> &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<Connection>
|
|
{
|
|
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);
|
|
|
|
std::vector<char> compress_buffers(const std::vector<char> &uncompressed_data,
|
|
const http::compression_type compression_type);
|
|
|
|
boost::asio::io_service::strand strand;
|
|
boost::asio::ip::tcp::socket TCP_socket;
|
|
RequestHandler &request_handler;
|
|
RequestParser request_parser;
|
|
boost::array<char, 8192> incoming_data_buffer;
|
|
http::request current_request;
|
|
http::reply current_reply;
|
|
std::vector<char> compressed_output;
|
|
// Header compression_header;
|
|
std::vector<boost::asio::const_buffer> output_buffer;
|
|
};
|
|
}
|
|
}
|
|
|
|
#endif // CONNECTION_HPP
|