15 #include <boost/scoped_ptr.hpp> 49 const unsigned short server_port,
51 const long request_timeout,
52 const long idle_timeout);
85 void acceptHandler(
const boost::system::error_code& ec);
95 boost::scoped_ptr<asiolink::TCPEndpoint> endpoint_;
104 long request_timeout_;
111 HttpListenerImpl::HttpListenerImpl(
IOService& io_service,
113 const unsigned short server_port,
115 const long request_timeout,
116 const long idle_timeout)
117 : io_service_(io_service), acceptor_(io_service),
118 endpoint_(), creator_factory_(creator_factory),
119 request_timeout_(request_timeout), idle_timeout_(idle_timeout) {
122 endpoint_.reset(
new TCPEndpoint(server_address, server_port));
126 << server_address <<
":" << server_port);
130 if (!creator_factory_) {
136 if (request_timeout_ <= 0) {
138 << request_timeout_);
142 if (idle_timeout_ <= 0) {
144 " timeout " << idle_timeout_);
156 acceptor_.
open(*endpoint_);
158 acceptor_.
bind(*endpoint_);
161 }
catch (
const boost::system::system_error& ex) {
164 "listening to the incoming HTTP requests: " << ex.
what());
177 HttpListenerImpl::accept() {
183 boost::bind(&HttpListenerImpl::acceptHandler,
this, _1);
191 connections_.
start(conn);
195 HttpListenerImpl::acceptHandler(
const boost::system::error_code&) {
203 const unsigned short server_port,
208 creator_factory, request_timeout.value_,
209 idle_timeout.value_)) {
218 return (impl_->getEndpoint().getAddress());
223 return (impl_->getEndpoint().getPort());
~HttpListener()
Destructor.
boost::shared_ptr< HttpResponseCreatorFactory > HttpResponseCreatorFactoryPtr
Pointer to the HttpResponseCreatorFactory.
Implementation of the HttpListener.
HttpListener(asiolink::IOService &io_service, const asiolink::IOAddress &server_address, const unsigned short server_port, const HttpResponseCreatorFactoryPtr &creator_factory, const RequestTimeout &request_timeout, const IdleTimeout &idle_timeout)
Constructor.
void start(const HttpConnectionPtr &connection)
Start new connection.
Accepts and handles a single HTTP connection.
void start()
Starts accepting new connections.
A generic error raised by the HttpListener class.
void start()
Starts accepting new connections.
void close() const
Closes the acceptor.
uint16_t getLocalPort() const
Returns local port on which server is listening.
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
The IOService class is a wrapper for the ASIO io_service class.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
The TCPEndpoint class is a concrete derived class of IOEndpoint that represents an endpoint of a TCP ...
void open(const EndpointType &endpoint)
Opens acceptor socket given the endpoint.
void setOption(const SettableSocketOption &socket_option)
Sets socket option.
boost::function< void(const boost::system::error_code &)> HttpAcceptorCallback
Type of the callback for the TCP acceptor used in this library.
boost::shared_ptr< HttpResponseCreator > HttpResponseCreatorPtr
Pointer to the HttpResponseCreator object.
Defines the logger used by the top-level component of kea-dhcp-ddns.
boost::asio::socket_base::reuse_address ReuseAddress
Represents SO_REUSEADDR socket option.
void bind(const EndpointType &endpoint)
Binds socket to an endpoint.
void stopAll()
Stops all connections and removes them from the pool.
void stop()
Stops all active connections and shuts down the service.
boost::shared_ptr< HttpConnection > HttpConnectionPtr
Pointer to the HttpConnection.
void stop()
Stops all active connections and shuts down the service.
void listen()
Starts listening new connections.
The IOAddress class represents an IP addresses (version agnostic)
asiolink::IOAddress getLocalAddress() const
Returns local address on which server is listening.
Pool of active HTTP connections.
HTTP request timeout value.
const TCPEndpoint & getEndpoint() const
Returns reference to the current listener endpoint.