Kea 1.5.0
connection.h
Go to the documentation of this file.
1// Copyright (C) 2017-2018 Internet Systems Consortium, Inc. ("ISC")
2//
3// This Source Code Form is subject to the terms of the Mozilla Public
4// License, v. 2.0. If a copy of the MPL was not distributed with this
5// file, You can obtain one at http://mozilla.org/MPL/2.0/.
6
7#ifndef HTTP_CONNECTION_H
8#define HTTP_CONNECTION_H
9
11#include <asiolink/io_service.h>
12#include <http/http_acceptor.h>
13#include <http/request_parser.h>
15#include <boost/function.hpp>
16#include <boost/enable_shared_from_this.hpp>
17#include <boost/system/error_code.hpp>
18#include <boost/shared_ptr.hpp>
19#include <array>
20#include <string>
21
22namespace isc {
23namespace http {
24
27public:
28 HttpConnectionError(const char* file, size_t line, const char* what) :
29 isc::Exception(file, line, what) { };
30};
31
36class HttpConnectionPool;
37
38class HttpConnection;
40typedef boost::shared_ptr<HttpConnection> HttpConnectionPtr;
41
43class HttpConnection : public boost::enable_shared_from_this<HttpConnection> {
44private:
45
48 typedef boost::function<void(boost::system::error_code ec, size_t length)>
49 SocketCallbackFunction;
50
54 class SocketCallback {
55 public:
56
61 SocketCallback(SocketCallbackFunction socket_callback)
62 : callback_(socket_callback) {
63 }
64
74 void operator()(boost::system::error_code ec, size_t length = 0);
75
76 private:
78 SocketCallbackFunction callback_;
79 };
80
81
82public:
83
98 HttpAcceptor& acceptor,
99 HttpConnectionPool& connection_pool,
100 const HttpResponseCreatorPtr& response_creator,
101 const HttpAcceptorCallback& callback,
102 const long request_timeout,
103 const long idle_timeout);
104
109
114 void asyncAccept();
115
117 void close();
118
127 void doRead();
128
129private:
130
136 void doWrite();
137
143 void asyncSendResponse(const ConstHttpResponsePtr& response);
144
152 void acceptorCallback(const boost::system::error_code& ec);
153
162 void socketReadCallback(boost::system::error_code ec,
163 size_t length);
164
169 void socketWriteCallback(boost::system::error_code ec,
170 size_t length);
171
178 void reinitProcessingState();
179
181 void setupRequestTimer();
182
184 void setupIdleTimer();
185
190 void requestTimeoutCallback();
191
192 void idleTimeoutCallback();
193
195 void stopThisConnection();
196
198 std::string getRemoteEndpointAddressAsText() const;
199
201 asiolink::IntervalTimer request_timer_;
202
204 long request_timeout_;
205
208 long idle_timeout_;
209
212
214 HttpAcceptor& acceptor_;
215
217 HttpConnectionPool& connection_pool_;
218
221 HttpResponseCreatorPtr response_creator_;
222
224 HttpRequestPtr request_;
225
227 HttpRequestParserPtr parser_;
228
230 HttpAcceptorCallback acceptor_callback_;
231
233 std::array<char, 32768> buf_;
234
236 std::string output_buf_;
237};
238
239} // end of namespace isc::http
240} // end of namespace isc
241
242#endif
This is a base class for exceptions thrown from the DNS library module.
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
Generic error reported within HttpConnection class.
Definition: connection.h:26
HttpConnectionError(const char *file, size_t line, const char *what)
Definition: connection.h:28
Pool of active HTTP connections.
Accepts and handles a single HTTP connection.
Definition: connection.h:43
void doRead()
Starts asynchronous read from the socket.
Definition: connection.cc:101
void close()
Closes the socket.
Definition: connection.cc:66
void asyncAccept()
Asynchronously accepts new connection.
Definition: connection.cc:84
~HttpConnection()
Destructor.
Definition: connection.cc:61
boost::shared_ptr< const HttpResponse > ConstHttpResponsePtr
Pointer to the const HttpResponse object.
Definition: response.h:84
boost::shared_ptr< HttpRequestParser > HttpRequestParserPtr
Pointer to the HttpRequestParser.
boost::function< void(const boost::system::error_code &)> HttpAcceptorCallback
Type of the callback for the TCP acceptor used in this library.
Definition: http_acceptor.h:19
boost::shared_ptr< HttpResponseCreator > HttpResponseCreatorPtr
Pointer to the HttpResponseCreator object.
boost::shared_ptr< HttpConnection > HttpConnectionPtr
Pointer to the HttpConnection.
Definition: connection.h:40
boost::shared_ptr< HttpRequest > HttpRequestPtr
Pointer to the HttpRequest object.
Definition: request.h:28
Defines the logger used by the top-level component of kea-dhcp-ddns.