Home
HTTP module

Server

HTTP server implementation.

Server

#include <icy/http/server.h>
class Server

Defined in src/http/include/icy/http/server.h:332

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

NameKindOwner
ServerConnectionfriendDeclared here
ConnectionvariableDeclared here
ShutdownvariableDeclared here
ServerfunctionDeclared here
ServerfunctionDeclared here
ServerfunctionDeclared here
ServerfunctionDeclared here
~ServerfunctionDeclared here
startfunctionDeclared here
stopfunctionDeclared here
setReusePortfunctionDeclared here
setMaxPooledConnectionsfunctionDeclared here
setKeepAliveTimeoutfunctionDeclared here
connectionCountfunctionDeclared here
addressfunctionDeclared here
dateCachefunctionDeclared here
_loopvariableDeclared here
_addressvariableDeclared here
_socketvariableDeclared here
_timervariableDeclared here
_factoryvariableDeclared here
_connectionsvariableDeclared here
_poolvariableDeclared here
_dateCachevariableDeclared here
_keepAliveTimeoutvariableDeclared here
_reusePortvariableDeclared here
createResponderfunctionDeclared here
onClientSocketAcceptfunctionDeclared here
onConnectionReadyfunctionDeclared here
onConnectionClosefunctionDeclared here
onSocketClosefunctionDeclared here
onTimerfunctionDeclared here
loopfunctionDeclared here
priorityvariableInherited from SocketAdapter
SocketAdapterfunctionInherited from SocketAdapter
~SocketAdapterfunctionInherited from SocketAdapter
sendfunctionInherited from SocketAdapter
sendfunctionInherited from SocketAdapter
sendOwnedfunctionInherited from SocketAdapter
sendOwnedfunctionInherited from SocketAdapter
sendPacketfunctionInherited from SocketAdapter
sendPacketfunctionInherited from SocketAdapter
sendPacketfunctionInherited from SocketAdapter
setSenderfunctionInherited from SocketAdapter
senderfunctionInherited from SocketAdapter
addReceiverfunctionInherited from SocketAdapter
removeReceiverfunctionInherited from SocketAdapter
hasReceiverfunctionInherited from SocketAdapter
receiversfunctionInherited from SocketAdapter
onSocketConnectfunctionInherited from SocketAdapter
onSocketRecvfunctionInherited from SocketAdapter
onSocketErrorfunctionInherited from SocketAdapter
onSocketClosefunctionInherited from SocketAdapter
_sendervariableInherited from SocketAdapter
_receiversvariableInherited from SocketAdapter
_dirtyvariableInherited from SocketAdapter
cleanupReceiversfunctionInherited from SocketAdapter

Inherited from SocketAdapter

KindNameDescription
variablepriorityThe priority of this adapter for STL sort operations.
functionSocketAdapterCreates the SocketAdapter.
function~SocketAdapter virtual noexceptDestroys the SocketAdapter.
functionsend virtualSends 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.
functionsend virtual
functionsendOwned virtualSends an owned payload buffer to the connected peer.
functionsendOwned virtual
functionsendPacket virtualSends 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.
functionsendPacket virtual
functionsendPacket virtualSends 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.
functionsetSender virtualSets the pointer to the outgoing data adapter. Send methods proxy data to this adapter by default.
functionsenderReturns the output SocketAdapter pointer.
functionaddReceiver virtualSets the pointer to the incoming data adapter. Events proxy data to this adapter by default.
functionremoveReceiver virtualRemove the given receiver.
functionhasReceiver virtualReturns true if the given receiver is connected.
functionreceiversReturns all currently registered input SocketAdapter pointers. Dead (removed) entries are excluded from the returned list.
functiononSocketConnect virtualCalled 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.
functiononSocketRecv virtualCalled when data is received from the socket. Forwards the event to all registered receivers in priority order.
functiononSocketError virtualCalled when the socket encounters an error. Forwards the event to all registered receivers in priority order.
functiononSocketClose virtualCalled when the socket is closed. Forwards the event to all registered receivers in priority order.
variable_sender
variable_receivers
variable_dirty
functioncleanupReceivers virtual

Friends

NameDescription
ServerConnection

ServerConnection

friend class ServerConnection

Defined in src/http/include/icy/http/server.h:435

Public Attributes

ReturnNameDescription
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.

Connection

LocalSignal< void(ServerConnection::Ptr)> Connection

Defined in src/http/include/icy/http/server.h:406

Signals when a new connection has been created. A reference to the new connection object is provided.


Shutdown

LocalSignal< void()> Shutdown

Defined in src/http/include/icy/http/server.h:409

Signals when the server is shutting down.

Public Methods

ReturnNameDescription
ServerConstructs an HTTP server on the given host and port using an internally created TCP socket.
ServerConstructs an HTTP server on the given address using an internally created TCP socket.
ServerConstructs 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.
ServerConstructs an HTTP server on the given address using a caller-supplied socket. The event loop is derived from the socket.
voidstartStart the HTTP server.
voidstopStop the HTTP server.
voidsetReusePort inlineEnable 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+).
voidsetMaxPooledConnections inlineSet the maximum number of pooled connections (default 128). Set to 0 to disable connection pooling entirely.
voidsetKeepAliveTimeout inlineSet 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_tconnectionCount const inlineReturn the number of active connections (all states).
net::Address &addressReturn the server bind address.
const DateCache &dateCache const inlineReturn 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:340

Constructs an HTTP server on the given host and port using an internally created TCP socket.

Parameters

  • 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

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:348

Constructs an HTTP server on the given address using an internally created TCP socket.

Parameters

  • address Bind address and port.

  • loop Event loop to use. Defaults to the default libuv loop.

  • factory Connection 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:358

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

  • host Bind address.

  • port TCP port to listen on.

  • socket Pre-created socket (e.g. SSLSocket for HTTPS).

  • factory Connection 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:367

Constructs an HTTP server on the given address using a caller-supplied socket. The event loop is derived from the socket.

Parameters

  • address Bind address and port.

  • socket Pre-created socket (e.g. SSLSocket for HTTPS).

  • factory Connection and responder factory.


start

void start()

Defined in src/http/include/icy/http/server.h:374

Start the HTTP server.


stop

void stop()

Defined in src/http/include/icy/http/server.h:377

Stop the HTTP server.


setReusePort

inline

inline void setReusePort(bool enable = true)

Defined in src/http/include/icy/http/server.h:384

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:388

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:393

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.


connectionCount

const inline

inline size_t connectionCount() const

Defined in src/http/include/icy/http/server.h:396

Return the number of active connections (all states).


address

net::Address & address()

Defined in src/http/include/icy/http/server.h:399

Return the server bind address.


dateCache

const inline

inline const DateCache & dateCache() const

Defined in src/http/include/icy/http/server.h:402

Return the cached Date header for use in responses.

Protected Attributes

ReturnNameDescription
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

_loop

uv::Loop * _loop

Defined in src/http/include/icy/http/server.h:424


_address

net::Address _address

Defined in src/http/include/icy/http/server.h:425


_socket

net::TCPSocket::Ptr _socket

Defined in src/http/include/icy/http/server.h:426


_timer

Timer _timer

Defined in src/http/include/icy/http/server.h:427


_factory

std::unique_ptr< ServerConnectionFactory > _factory

Defined in src/http/include/icy/http/server.h:428


_connections

std::unordered_map< ServerConnection *, ServerConnection::Ptr > _connections

Defined in src/http/include/icy/http/server.h:429


_pool

ConnectionPool _pool

Defined in src/http/include/icy/http/server.h:430


_dateCache

DateCache _dateCache

Defined in src/http/include/icy/http/server.h:431


_keepAliveTimeout

int _keepAliveTimeout {30}

Defined in src/http/include/icy/http/server.h:432


_reusePort

bool _reusePort {false}

Defined in src/http/include/icy/http/server.h:433

Protected Methods

ReturnNameDescription
std::unique_ptr< ServerResponder >createResponder
voidonClientSocketAccept
voidonConnectionReady
voidonConnectionClose
boolonSocketClose virtualCalled when the socket is closed. Forwards the event to all registered receivers in priority order.
voidonTimer
uv::Loop *loop const inlineReturn the event loop this server runs on.

createResponder

std::unique_ptr< ServerResponder > createResponder(ServerConnection & conn)

Defined in src/http/include/icy/http/server.h:412


onClientSocketAccept

void onClientSocketAccept(const net::TCPSocket::Ptr & socket)

Defined in src/http/include/icy/http/server.h:414


onConnectionReady

void onConnectionReady(ServerConnection & conn)

Defined in src/http/include/icy/http/server.h:415


onConnectionClose

void onConnectionClose(ServerConnection & conn)

Defined in src/http/include/icy/http/server.h:416


onSocketClose

virtual

virtual bool onSocketClose(net::Socket & socket)

Defined in src/http/include/icy/http/server.h:417

Called when the socket is closed. Forwards the event to all registered receivers in priority order.

Parameters

  • socket The 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:418


loop

const inline

inline uv::Loop * loop() const

Defined in src/http/include/icy/http/server.h:421

Return the event loop this server runs on.