Server
Server
#include <icy/http/server.h>class ServerDefined in src/http/include/icy/http/server.h:333
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.
List of all members
| Name | Kind | Owner |
|---|---|---|
ServerConnection | friend | Declared here |
Connection | variable | Declared here |
Shutdown | variable | Declared here |
Server | function | Declared here |
Server | function | Declared here |
Server | function | Declared here |
Server | function | Declared here |
~Server | function | Declared here |
start | function | Declared here |
stop | function | Declared here |
setReusePort | function | Declared here |
setMaxPooledConnections | function | Declared here |
setKeepAliveTimeout | function | Declared here |
setWebSocketOriginValidator | function | Declared here |
connectionCount | function | Declared here |
address | function | Declared here |
dateCache | function | Declared here |
_loop | variable | Declared here |
_address | variable | Declared here |
_socket | variable | Declared here |
_timer | variable | Declared here |
_factory | variable | Declared here |
_webSocketOriginValidator | variable | Declared here |
_connections | variable | Declared here |
_pool | variable | Declared here |
_dateCache | variable | Declared here |
_keepAliveTimeout | variable | Declared here |
_reusePort | variable | Declared here |
createResponder | function | Declared here |
onClientSocketAccept | function | Declared here |
onConnectionReady | function | Declared here |
onConnectionClose | function | Declared here |
onSocketClose | function | Declared here |
onTimer | function | Declared here |
isWebSocketOriginAllowed | function | Declared here |
loop | function | Declared here |
WebSocketOriginValidator | typedef | Declared here |
priority | variable | Inherited from SocketAdapter |
SocketAdapter | function | Inherited from SocketAdapter |
~SocketAdapter | function | Inherited from SocketAdapter |
send | function | Inherited from SocketAdapter |
send | function | Inherited from SocketAdapter |
sendOwned | function | Inherited from SocketAdapter |
sendOwned | function | Inherited from SocketAdapter |
sendPacket | function | Inherited from SocketAdapter |
sendPacket | function | Inherited from SocketAdapter |
sendPacket | function | Inherited from SocketAdapter |
setSender | function | Inherited from SocketAdapter |
sender | function | Inherited from SocketAdapter |
addReceiver | function | Inherited from SocketAdapter |
removeReceiver | function | Inherited from SocketAdapter |
hasReceiver | function | Inherited from SocketAdapter |
receivers | function | Inherited from SocketAdapter |
onSocketConnect | function | Inherited from SocketAdapter |
onSocketRecv | function | Inherited from SocketAdapter |
onSocketError | function | Inherited from SocketAdapter |
onSocketClose | function | Inherited from SocketAdapter |
_sender | variable | Inherited from SocketAdapter |
_receivers | variable | Inherited from SocketAdapter |
_dirty | variable | Inherited from SocketAdapter |
_dispatchDepth | variable | Inherited from SocketAdapter |
cleanupReceivers | function | Inherited from SocketAdapter |
Inherited from SocketAdapter
| Kind | Name | Description |
|---|---|---|
variable | priority | The priority of this adapter for STL sort operations. |
function | SocketAdapter | Creates the SocketAdapter. |
function | ~SocketAdapter virtual noexcept | Destroys the SocketAdapter. |
function | send virtual | Sends the given data buffer to the connected peer. Returns the number of bytes sent or -1 on error. No exception will be thrown. For TCP sockets the given peer address must match the connected peer address. |
function | send virtual | |
function | sendOwned virtual | Sends an owned payload buffer to the connected peer. |
function | sendOwned virtual | |
function | sendPacket virtual | Sends the given packet to the connected peer. Returns the number of bytes sent or -1 on error. No exception will be thrown. For TCP sockets the given peer address must match the connected peer address. |
function | sendPacket virtual | |
function | sendPacket virtual | Sends the given packet to the connected peer. This method provides delegate compatibility, and unlike other send methods throws an exception if the underlying socket is closed. |
function | setSender virtual | Sets the pointer to the outgoing data adapter. Send methods proxy data to this adapter by default. |
function | sender | Returns the output SocketAdapter pointer. |
function | addReceiver virtual | Sets the pointer to the incoming data adapter. Events proxy data to this adapter by default. |
function | removeReceiver virtual | Remove the given receiver. |
function | hasReceiver virtual | Returns true if the given receiver is connected. |
function | receivers | Returns all currently registered input SocketAdapter pointers. Dead (removed) entries are excluded from the returned list. |
function | onSocketConnect virtual | Called when the socket establishes a connection. Forwards the event to all registered receivers in priority order. Override to intercept before the application sees the event. |
function | onSocketRecv virtual | Called when data is received from the socket. Forwards the event to all registered receivers in priority order. |
function | onSocketError virtual | Called when the socket encounters an error. Forwards the event to all registered receivers in priority order. |
function | onSocketClose virtual | Called when the socket is closed. Forwards the event to all registered receivers in priority order. |
variable | _sender | |
variable | _receivers | |
variable | _dirty | |
variable | _dispatchDepth | |
function | cleanupReceivers virtual |
Friends
| Name | Description |
|---|---|
ServerConnection |
ServerConnection
friend class ServerConnectionDefined in src/http/include/icy/http/server.h:444
Public Attributes
| 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. |
Connection
LocalSignal< void(ServerConnection::Ptr)> ConnectionDefined in src/http/include/icy/http/server.h:413
Signals when a new connection has been created. A reference to the new connection object is provided.
Shutdown
LocalSignal< void()> ShutdownDefined in src/http/include/icy/http/server.h:416
Signals when the server is shutting down.
Public Methods
| 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. |
void | setWebSocketOriginValidator | Set an optional WebSocket Origin validator. When set, upgrade requests rejected by the validator receive 403 before the 101 handshake. |
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
Server(const std::string & host, short port, uv::Loop * loop = uv::defaultLoop(), std::unique_ptr< ServerConnectionFactory > factory = std::make_unique< ServerConnectionFactory >())Defined in src/http/include/icy/http/server.h:343
Constructs an HTTP server on the given host and port using an internally created TCP socket.
Parameters
hostBind address (e.g. "0.0.0.0" or "127.0.0.1").portTCP port to listen on.loopEvent loop to use. Defaults to the default libuv loop.factoryConnection and responder factory. Defaults to the base factory.
Server
Server(const net::Address & address, uv::Loop * loop = uv::defaultLoop(), std::unique_ptr< ServerConnectionFactory > factory = std::make_unique< ServerConnectionFactory >())Defined in src/http/include/icy/http/server.h:351
Constructs an HTTP server on the given address using an internally created TCP socket.
Parameters
addressBind address and port.loopEvent loop to use. Defaults to the default libuv loop.factoryConnection and responder factory.
Server
Server(const std::string & host, short port, net::TCPSocket::Ptr socket, std::unique_ptr< ServerConnectionFactory > factory = std::make_unique< ServerConnectionFactory >())Defined in src/http/include/icy/http/server.h:361
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.
Parameters
hostBind address.portTCP port to listen on.socketPre-created socket (e.g. SSLSocket for HTTPS).factoryConnection and responder factory.
Server
Server(const net::Address & address, net::TCPSocket::Ptr socket, std::unique_ptr< ServerConnectionFactory > factory = std::make_unique< ServerConnectionFactory >())Defined in src/http/include/icy/http/server.h:370
Constructs an HTTP server on the given address using a caller-supplied socket. The event loop is derived from the socket.
Parameters
addressBind address and port.socketPre-created socket (e.g. SSLSocket for HTTPS).factoryConnection and responder factory.
start
void start()Defined in src/http/include/icy/http/server.h:377
Start the HTTP server.
stop
void stop()Defined in src/http/include/icy/http/server.h:380
Stop the HTTP server.
setReusePort
inline
inline void setReusePort(bool enable = true)Defined in src/http/include/icy/http/server.h:387
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+).
setMaxPooledConnections
inline
inline void setMaxPooledConnections(size_t n)Defined in src/http/include/icy/http/server.h:391
Set the maximum number of pooled connections (default 128). Set to 0 to disable connection pooling entirely.
setKeepAliveTimeout
inline
inline void setKeepAliveTimeout(int seconds)Defined in src/http/include/icy/http/server.h:396
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.
setWebSocketOriginValidator
void setWebSocketOriginValidator(WebSocketOriginValidator validator)Defined in src/http/include/icy/http/server.h:400
Set an optional WebSocket Origin validator. When set, upgrade requests rejected by the validator receive 403 before the 101 handshake.
connectionCount
const inline
inline size_t connectionCount() constDefined in src/http/include/icy/http/server.h:403
Return the number of active connections (all states).
address
net::Address & address()Defined in src/http/include/icy/http/server.h:406
Return the server bind address.
dateCache
const inline
inline const DateCache & dateCache() constDefined in src/http/include/icy/http/server.h:409
Return the cached Date header for use in responses.
Protected Attributes
| Return | Name | Description |
|---|---|---|
uv::Loop * | _loop | |
net::Address | _address | |
net::TCPSocket::Ptr | _socket | |
Timer | _timer | |
std::unique_ptr< ServerConnectionFactory > | _factory | |
WebSocketOriginValidator | _webSocketOriginValidator | |
std::unordered_map< ServerConnection *, ServerConnection::Ptr > | _connections | |
ConnectionPool | _pool | |
DateCache | _dateCache | |
int | _keepAliveTimeout | |
bool | _reusePort |
_loop
uv::Loop * _loopDefined in src/http/include/icy/http/server.h:432
_address
net::Address _addressDefined in src/http/include/icy/http/server.h:433
_socket
net::TCPSocket::Ptr _socketDefined in src/http/include/icy/http/server.h:434
_timer
Timer _timerDefined in src/http/include/icy/http/server.h:435
_factory
std::unique_ptr< ServerConnectionFactory > _factoryDefined in src/http/include/icy/http/server.h:436
_webSocketOriginValidator
WebSocketOriginValidator _webSocketOriginValidatorDefined in src/http/include/icy/http/server.h:437
_connections
std::unordered_map< ServerConnection *, ServerConnection::Ptr > _connectionsDefined in src/http/include/icy/http/server.h:438
_pool
ConnectionPool _poolDefined in src/http/include/icy/http/server.h:439
_dateCache
DateCache _dateCacheDefined in src/http/include/icy/http/server.h:440
_keepAliveTimeout
int _keepAliveTimeout {30}Defined in src/http/include/icy/http/server.h:441
_reusePort
bool _reusePort {false}Defined in src/http/include/icy/http/server.h:442
Protected Methods
| 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 | |
bool | isWebSocketOriginAllowed const | |
uv::Loop * | loop const inline | Return the event loop this server runs on. |
createResponder
std::unique_ptr< ServerResponder > createResponder(ServerConnection & conn)Defined in src/http/include/icy/http/server.h:419
onClientSocketAccept
void onClientSocketAccept(const net::TCPSocket::Ptr & socket)Defined in src/http/include/icy/http/server.h:421
onConnectionReady
void onConnectionReady(ServerConnection & conn)Defined in src/http/include/icy/http/server.h:422
onConnectionClose
void onConnectionClose(ServerConnection & conn)Defined in src/http/include/icy/http/server.h:423
onSocketClose
virtual
virtual bool onSocketClose(net::Socket & socket)Defined in src/http/include/icy/http/server.h:424
Called when the socket is closed. Forwards the event to all registered receivers in priority order.
Parameters
socketThe socket that was closed.
Returns
true to stop propagation to subsequent receivers.
Reimplements
onTimer
void onTimer()Defined in src/http/include/icy/http/server.h:425
isWebSocketOriginAllowed
const
bool isWebSocketOriginAllowed(const Request & request) constDefined in src/http/include/icy/http/server.h:426
loop
const inline
inline uv::Loop * loop() constDefined in src/http/include/icy/http/server.h:429
Return the event loop this server runs on.
Public Types
| Name | Description |
|---|---|
WebSocketOriginValidator |
WebSocketOriginValidator
using WebSocketOriginValidator = std::function< bool(const Request &)>