Kea 2.7.3
|
Implementation of the HttpListener. More...
#include <listener_impl.h>
Public Member Functions | |
HttpListenerImpl (const asiolink::IOServicePtr &io_service, const asiolink::IOAddress &server_address, const unsigned short server_port, const asiolink::TlsContextPtr &tls_context, const HttpResponseCreatorFactoryPtr &creator_factory, const long request_timeout, const long idle_timeout) | |
Constructor. | |
virtual | ~HttpListenerImpl () |
Virtual destructor. | |
void | addExternalSockets (bool use_external) |
Use external sockets flag. | |
const asiolink::TCPEndpoint & | getEndpoint () const |
Returns reference to the current listener endpoint. | |
int | getNative () const |
file descriptor of the underlying acceptor socket. | |
void | start () |
Starts accepting new connections. | |
void | stop () |
Stops all active connections and shuts down the service. | |
Protected Member Functions | |
void | accept () |
Creates HttpConnection instance and adds it to the pool of active connections. | |
void | acceptHandler (const boost::system::error_code &ec) |
Callback invoked when the new connection is accepted. | |
virtual HttpConnectionPtr | createConnection (const HttpResponseCreatorPtr &response_creator, const HttpAcceptorCallback &callback) |
Creates an instance of the HttpConnection . | |
Protected Attributes | |
HttpAcceptorPtr | acceptor_ |
Acceptor instance. | |
HttpConnectionPool | connections_ |
Pool of active connections. | |
HttpResponseCreatorFactoryPtr | creator_factory_ |
Pointer to the HttpResponseCreatorFactory. | |
boost::scoped_ptr< asiolink::TCPEndpoint > | endpoint_ |
Pointer to the endpoint representing IP address and port on which the service is running. | |
long | idle_timeout_ |
Timeout after which idle persistent connection is closed by the server. | |
asiolink::IOServicePtr | io_service_ |
Pointer to the IO service. | |
long | request_timeout_ |
Timeout for HTTP Request Timeout desired. | |
asiolink::TlsContextPtr | tls_context_ |
TLS context. | |
bool | use_external_ |
Use external sockets flag. | |
Implementation of the HttpListener.
Definition at line 22 of file listener_impl.h.
isc::http::HttpListenerImpl::HttpListenerImpl | ( | const asiolink::IOServicePtr & | io_service, |
const asiolink::IOAddress & | server_address, | ||
const unsigned short | server_port, | ||
const asiolink::TlsContextPtr & | tls_context, | ||
const HttpResponseCreatorFactoryPtr & | creator_factory, | ||
const long | request_timeout, | ||
const long | idle_timeout ) |
Constructor.
This constructor creates new server endpoint using the specified IP address and port. It also validates other specified parameters.
This constructor does not start accepting new connections! To start accepting connections run HttpListener::start.
io_service | IO service to be used by the listener. |
server_address | Address on which the HTTP service should run. |
server_port | Port number on which the HTTP service should run. |
tls_context | TLS context. |
creator_factory | Pointer to the caller-defined HttpResponseCreatorFactory derivation which should be used to create HttpResponseCreator instances. |
request_timeout | Timeout after which the HTTP Request Timeout is generated. |
idle_timeout | Timeout after which an idle persistent HTTP connection is closed by the server. |
HttpListenerError | when any of the specified parameters is invalid. |
Definition at line 21 of file listener_impl.cc.
References acceptor_, creator_factory_, endpoint_, idle_timeout_, isc_throw, and request_timeout_.
|
inlinevirtual |
Virtual destructor.
Definition at line 56 of file listener_impl.h.
|
protected |
Creates HttpConnection instance and adds it to the pool of active connections.
The next accepted connection will be handled by this instance.
Definition at line 113 of file listener_impl.cc.
References acceptHandler(), connections_, createConnection(), creator_factory_, isc::http::HttpConnectionPool::start(), and use_external_.
Referenced by acceptHandler(), and start().
|
protected |
Callback invoked when the new connection is accepted.
It calls HttpListener::accept
to create new HttpConnection
instance.
ec | Error code passed to the handler. This is currently ignored. |
Definition at line 131 of file listener_impl.cc.
References accept().
Referenced by accept().
void isc::http::HttpListenerImpl::addExternalSockets | ( | bool | use_external | ) |
Use external sockets flag.
Add sockets as external sockets of the interface manager so available I/O on them makes a waiting select to return.
use_external | True add external sockets. |
Definition at line 79 of file listener_impl.cc.
References use_external_.
|
protectedvirtual |
Creates an instance of the HttpConnection
.
This method is virtual so as it can be overridden when customized connections are to be used, e.g. in case of unit testing.
response_creator | Pointer to the response creator object used to create HTTP response from the HTTP request received. |
callback | Callback invoked when new connection is accepted. |
Definition at line 138 of file listener_impl.cc.
References acceptor_, connections_, idle_timeout_, io_service_, request_timeout_, and tls_context_.
Referenced by accept().
const TCPEndpoint & isc::http::HttpListenerImpl::getEndpoint | ( | ) | const |
Returns reference to the current listener endpoint.
Definition at line 69 of file listener_impl.cc.
References endpoint_.
int isc::http::HttpListenerImpl::getNative | ( | ) | const |
file descriptor of the underlying acceptor socket.
Definition at line 74 of file listener_impl.cc.
References acceptor_.
void isc::http::HttpListenerImpl::start | ( | ) |
Starts accepting new connections.
This method starts accepting and handling new HTTP connections on the IP address and port number specified in the constructor.
If the method is invoked successfully, it must not be invoked again until HttpListener::stop is called.
HttpListenerError | if an error occurred. |
Definition at line 84 of file listener_impl.cc.
References accept(), acceptor_, endpoint_, isc::dhcp::IfaceMgr::instance(), isc_throw, stop(), use_external_, and isc::Exception::what().
void isc::http::HttpListenerImpl::stop | ( | ) |
Stops all active connections and shuts down the service.
Definition at line 104 of file listener_impl.cc.
References acceptor_, connections_, isc::dhcp::IfaceMgr::instance(), isc::http::HttpConnectionPool::stopAll(), and use_external_.
Referenced by start().
|
protected |
Acceptor instance.
Definition at line 123 of file listener_impl.h.
Referenced by HttpListenerImpl(), createConnection(), getNative(), start(), and stop().
|
protected |
Pool of active connections.
Definition at line 130 of file listener_impl.h.
Referenced by accept(), createConnection(), and stop().
|
protected |
Pointer to the HttpResponseCreatorFactory.
Definition at line 133 of file listener_impl.h.
Referenced by HttpListenerImpl(), and accept().
|
protected |
Pointer to the endpoint representing IP address and port on which the service is running.
Definition at line 127 of file listener_impl.h.
Referenced by HttpListenerImpl(), getEndpoint(), and start().
|
protected |
Timeout after which idle persistent connection is closed by the server.
Definition at line 140 of file listener_impl.h.
Referenced by HttpListenerImpl(), and createConnection().
|
protected |
Pointer to the IO service.
Definition at line 117 of file listener_impl.h.
Referenced by createConnection().
|
protected |
Timeout for HTTP Request Timeout desired.
Definition at line 136 of file listener_impl.h.
Referenced by HttpListenerImpl(), and createConnection().
|
protected |
|
protected |
Use external sockets flag.
Definition at line 143 of file listener_impl.h.
Referenced by accept(), addExternalSockets(), start(), and stop().