HTTP module

ServerConnection

HTTP server connection.

ServerConnection

#include <icy/http/server.h>

Inherits: Connection

HTTP server connection.

Public Attributes

ReturnNameDescription
LocalSignal< void(ServerConnection &, const MutableBuffer &)>PayloadSignals when raw data is received.
LocalSignal< void(ServerConnection &)>CloseSignals when the connection is closed.

Payload

LocalSignal< void(ServerConnection &, const MutableBuffer &)> Payload

Signals when raw data is received.


Close

LocalSignal< void(ServerConnection &)> Close

Signals when the connection is closed.

Public Methods

ReturnNameDescription
ServerConnectionCreates a ServerConnection attached to the given server and socket.
Server &serverReturns the owning Server instance.
ServerConnectionStatestate const inlineReturns the current server-side connection state.
ServerConnectionModemode const inlineReturns the current transport mode.
boolupgraded const inlineReturns true if the connection has been upgraded (e.g. to WebSocket).
boolstreaming const inlineReturns true if the connection is in long-lived streaming mode.
boolidleTimeoutEnabled constReturns true if the server idle timer is allowed to reap this connection.
boolreusableForPool constReturns true if the closed connection can be returned to the reuse pool.
voidmarkActive virtual inlineRefresh the idle timer.
voidresetReset this connection for reuse with a new socket. Called by the connection pool to avoid allocating a new ServerConnection.
voidtouch inlineUpdate the last activity timestamp.
doubleidleSeconds const inlineReturn seconds since last activity.
voidbeginStreaming virtualExplicitly mark the response as long-lived streaming. Streaming connections are excluded from the keep-alive idle reaper.
voidendStreaming virtualExit streaming mode and return to the given HTTP state.
voidendStreaming
ssize_tsendHeader virtualSend the outgoing HTTP header.
voidclose virtualClose the connection with an explicit terminal state transition.

ServerConnection

ServerConnection(Server & server, net::TCPSocket::Ptr socket)

Creates a ServerConnection attached to the given server and socket.

Parameters

  • server The owning HTTP server instance.

  • socket The accepted TCP socket for this connection.


server

Server & server()

Returns the owning Server instance.


state

const inline

inline ServerConnectionState state() const

Returns the current server-side connection state.


mode

const inline

inline ServerConnectionMode mode() const

Returns the current transport mode.


upgraded

const inline

inline bool upgraded() const

Returns true if the connection has been upgraded (e.g. to WebSocket).


streaming

const inline

inline bool streaming() const

Returns true if the connection is in long-lived streaming mode.


idleTimeoutEnabled

const

bool idleTimeoutEnabled() const

Returns true if the server idle timer is allowed to reap this connection.


reusableForPool

const

bool reusableForPool() const

Returns true if the closed connection can be returned to the reuse pool.


markActive

virtual inline

virtual inline void markActive()

Refresh the idle timer.


reset

void reset(net::TCPSocket::Ptr socket)

Reset this connection for reuse with a new socket. Called by the connection pool to avoid allocating a new ServerConnection.


touch

inline

inline void touch()

Update the last activity timestamp.


idleSeconds

const inline

inline double idleSeconds() const

Return seconds since last activity.


beginStreaming

virtual

virtual void beginStreaming()

Explicitly mark the response as long-lived streaming. Streaming connections are excluded from the keep-alive idle reaper.


endStreaming

virtual

virtual void endStreaming()

Exit streaming mode and return to the given HTTP state.


endStreaming

void endStreaming(ServerConnectionState nextState)

sendHeader

virtual

virtual ssize_t sendHeader()

Send the outgoing HTTP header.


close

virtual

virtual void close()

Close the connection with an explicit terminal state transition.

Protected Attributes

ReturnNameDescription
Server &_server
std::unique_ptr< ServerResponder >_responder
std::time_t_lastActivity
ServerConnectionState_state
ServerConnectionMode_mode

_server

Server & _server

_responder

std::unique_ptr< ServerResponder > _responder

_lastActivity

std::time_t _lastActivity {0}

_state

ServerConnectionState _state {}

_mode

ServerConnectionMode _mode {}

Protected Methods

ReturnNameDescription
voidonHeaders virtualCalled when the incoming HTTP headers have been fully parsed.
voidonPayload virtualCalled for each chunk of incoming body data after headers are complete.
voidonComplete virtualCalled when the incoming HTTP message is fully received.
voidonClose virtualCalled when the connection is closed.
http::Message *incomingHeader virtualReturns the incoming HTTP message header (request or response depending on role).
http::Message *outgoingHeader virtualReturns the outgoing HTTP message header (request or response depending on role).
voidsetState
boolrequestHasBody const
boolresponseLooksStreaming const

onHeaders

virtual

virtual void onHeaders()

Called when the incoming HTTP headers have been fully parsed.


onPayload

virtual

virtual void onPayload(const MutableBuffer & buffer)

Called for each chunk of incoming body data after headers are complete.

Parameters

  • buffer Buffer containing the received data chunk.

onComplete

virtual

virtual void onComplete()

Called when the incoming HTTP message is fully received.


onClose

virtual

virtual void onClose()

Called when the connection is closed.


incomingHeader

virtual

virtual http::Message * incomingHeader()

Returns the incoming HTTP message header (request or response depending on role).


outgoingHeader

virtual

virtual http::Message * outgoingHeader()

Returns the outgoing HTTP message header (request or response depending on role).


setState

void setState(ServerConnectionState state)

requestHasBody

const

bool requestHasBody() const

responseLooksStreaming

const

bool responseLooksStreaming() const

Public Types

NameDescription
Ptr

Ptr

std::shared_ptr< ServerConnection > Ptr()