From dba214ecf3126f91697b58e4dde679e39353aadf Mon Sep 17 00:00:00 2001 From: Marcin Siodelski Date: Mon, 9 Jan 2017 20:19:46 +0100 Subject: [5099] Implemented HttpListener and other classes. - HttpConnection - HttpConnectionPool --- src/lib/http/connection.h | 102 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 102 insertions(+) create mode 100644 src/lib/http/connection.h (limited to 'src/lib/http/connection.h') diff --git a/src/lib/http/connection.h b/src/lib/http/connection.h new file mode 100644 index 0000000000..5304a1392f --- /dev/null +++ b/src/lib/http/connection.h @@ -0,0 +1,102 @@ +// Copyright (C) 2017 Internet Systems Consortium, Inc. ("ISC") +// +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at http://mozilla.org/MPL/2.0/. + +#ifndef HTTP_CONNECTION_H +#define HTTP_CONNECTION_H + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace isc { +namespace http { + +class HttpConnectionPool; + +class HttpConnection; +typedef boost::shared_ptr HttpConnectionPtr; + +class HttpConnection : public boost::enable_shared_from_this { +private: + + typedef boost::function + SocketCallbackFunction; + + class SocketCallback { + public: + + SocketCallback(SocketCallbackFunction socket_callback) + : callback_(socket_callback) { + } + + void operator()(boost::system::error_code ec, size_t length = 0); + + private: + SocketCallbackFunction callback_; + }; + + +public: + + HttpConnection(asiolink::IOService& io_service, + HttpAcceptor& acceptor, + HttpConnectionPool& connection_pool, + const HttpResponseCreatorPtr& response_creator, + const HttpAcceptorCallback& callback); + + ~HttpConnection(); + + void asyncAccept(); + + void close(); + + void doRead(); + + void doWrite(); + + void acceptorCallback(const boost::system::error_code& ec); + + void socketReadCallback(boost::system::error_code ec, + size_t length); + + void socketWriteCallback(boost::system::error_code ec, + size_t length); + +private: + + asiolink::TCPSocket socket_; + + SocketCallback socket_callback_; + + SocketCallback socket_write_callback_; + + HttpAcceptor& acceptor_; + + HttpConnectionPool& connection_pool_; + + HttpResponseCreatorPtr response_creator_; + + HttpRequestPtr request_; + + HttpRequestParserPtr parser_; + + HttpAcceptorCallback acceptor_callback_; + + std::array buf_; + + std::string output_buf_; +}; + +} +} + +#endif -- cgit v1.2.3