#include <icy/http/server.h>Inherits:
SocketAdapter
HTTP server implementation.
This HTTP server is not strictly standards compliant. It was created to be a fast (nocopy where possible) solution for streaming media to web browsers.
| Return | Name | Description |
|---|---|---|
LocalSignal< void(ServerConnection::Ptr)> | Connection | Signals when a new connection has been created. A reference to the new connection object is provided. |
LocalSignal< void()> | Shutdown | Signals when the server is shutting down. |
LocalSignal< void(ServerConnection::Ptr)> ConnectionSignals when a new connection has been created. A reference to the new connection object is provided.
LocalSignal< void()> ShutdownSignals when the server is shutting down.
| Return | Name | Description |
|---|---|---|
Server | Constructs an HTTP server on the given host and port using an internally created TCP socket. | |
Server | Constructs an HTTP server on the given address using an internally created TCP socket. | |
Server | Constructs an HTTP server on the given host and port using a caller-supplied socket. Useful for HTTPS by passing an SSLSocket. The event loop is derived from the socket. | |
Server | Constructs an HTTP server on the given address using a caller-supplied socket. The event loop is derived from the socket. | |
void | start | Start the HTTP server. |
void | stop | Stop the HTTP server. |
void | setReusePort inline | Enable SO_REUSEPORT for multicore server instances. Must be called before start(). Allows multiple server instances to bind the same address:port with kernel-level load balancing (Linux 3.9+). |
void | setMaxPooledConnections inline | Set the maximum number of pooled connections (default 128). Set to 0 to disable connection pooling entirely. |
void | setKeepAliveTimeout inline | Set the keep-alive idle timeout in seconds (default 30). Connections idle longer than this are closed by the timer. Set to 0 to disable idle timeout. |
size_t | connectionCount const inline | Return the number of active connections (all states). |
net::Address & | address | Return the server bind address. |
const DateCache & | dateCache const inline | Return the cached Date header for use in responses. |
Server(const std::string & host, short port, uv::Loop * loop, std::unique_ptr< ServerConnectionFactory > factory)Constructs an HTTP server on the given host and port using an internally created TCP socket.
host Bind address (e.g. "0.0.0.0" or "127.0.0.1").
port TCP port to listen on.
loop Event loop to use. Defaults to the default libuv loop.
factory Connection and responder factory. Defaults to the base factory.
Server(const net::Address & address, uv::Loop * loop, std::unique_ptr< ServerConnectionFactory > factory)Constructs an HTTP server on the given address using an internally created TCP socket.
address Bind address and port.
loop Event loop to use. Defaults to the default libuv loop.
factory Connection and responder factory.
Server(const std::string & host, short port, net::TCPSocket::Ptr socket, std::unique_ptr< ServerConnectionFactory > factory)Constructs an HTTP server on the given host and port using a caller-supplied socket. Useful for HTTPS by passing an SSLSocket. The event loop is derived from the socket.
host Bind address.
port TCP port to listen on.
socket Pre-created socket (e.g. SSLSocket for HTTPS).
factory Connection and responder factory.
Server(const net::Address & address, net::TCPSocket::Ptr socket, std::unique_ptr< ServerConnectionFactory > factory)Constructs an HTTP server on the given address using a caller-supplied socket. The event loop is derived from the socket.
address Bind address and port.
socket Pre-created socket (e.g. SSLSocket for HTTPS).
factory Connection and responder factory.
void start()Start the HTTP server.
void stop()Stop the HTTP server.
inline
inline void setReusePort(bool enable)Enable SO_REUSEPORT for multicore server instances. Must be called before start(). Allows multiple server instances to bind the same address:port with kernel-level load balancing (Linux 3.9+).
inline
inline void setMaxPooledConnections(size_t n)Set the maximum number of pooled connections (default 128). Set to 0 to disable connection pooling entirely.
inline
inline void setKeepAliveTimeout(int seconds)Set the keep-alive idle timeout in seconds (default 30). Connections idle longer than this are closed by the timer. Set to 0 to disable idle timeout.
const inline
inline size_t connectionCount() constReturn the number of active connections (all states).
net::Address & address()Return the server bind address.
const inline
inline const DateCache & dateCache() constReturn the cached Date header for use in responses.
| Return | Name | Description |
|---|---|---|
uv::Loop * | _loop | |
net::Address | _address | |
net::TCPSocket::Ptr | _socket | |
Timer | _timer | |
std::unique_ptr< ServerConnectionFactory > | _factory | |
std::unordered_map< ServerConnection *, ServerConnection::Ptr > | _connections | |
ConnectionPool | _pool | |
DateCache | _dateCache | |
int | _keepAliveTimeout | |
bool | _reusePort |
uv::Loop * _loopnet::Address _addressnet::TCPSocket::Ptr _socketTimer _timerstd::unique_ptr< ServerConnectionFactory > _factorystd::unordered_map< ServerConnection *, ServerConnection::Ptr > _connectionsConnectionPool _poolDateCache _dateCacheint _keepAliveTimeout {30}bool _reusePort {false}| Return | Name | Description |
|---|---|---|
std::unique_ptr< ServerResponder > | createResponder | |
void | onClientSocketAccept | |
void | onConnectionReady | |
void | onConnectionClose | |
bool | onSocketClose virtual | Called when the socket is closed. Forwards the event to all registered receivers in priority order. |
void | onTimer | |
uv::Loop * | loop const inline | Return the event loop this server runs on. |
std::unique_ptr< ServerResponder > createResponder(ServerConnection & conn)void onClientSocketAccept(const net::TCPSocket::Ptr & socket)void onConnectionReady(ServerConnection & conn)void onConnectionClose(ServerConnection & conn)virtual
virtual bool onSocketClose(net::Socket & socket)Called when the socket is closed. Forwards the event to all registered receivers in priority order.
socket The socket that was closed.true to stop propagation to subsequent receivers.
void onTimer()const inline
inline uv::Loop * loop() constReturn the event loop this server runs on.