ServerConnection
ServerConnection
#include <icy/http/server.h>Inherits:
Connection
HTTP server connection.
Public Attributes
| Return | Name | Description |
|---|---|---|
LocalSignal< void(ServerConnection &, const MutableBuffer &)> | Payload | Signals when raw data is received. |
LocalSignal< void(ServerConnection &)> | Close | Signals when the connection is closed. |
Payload
LocalSignal< void(ServerConnection &, const MutableBuffer &)> PayloadSignals when raw data is received.
Close
LocalSignal< void(ServerConnection &)> CloseSignals when the connection is closed.
Public Methods
| Return | Name | Description |
|---|---|---|
ServerConnection | Creates a ServerConnection attached to the given server and socket. | |
Server & | server | Returns the owning Server instance. |
ServerConnectionState | state const inline | Returns the current server-side connection state. |
ServerConnectionMode | mode const inline | Returns the current transport mode. |
bool | upgraded const inline | Returns true if the connection has been upgraded (e.g. to WebSocket). |
bool | streaming const inline | Returns true if the connection is in long-lived streaming mode. |
bool | idleTimeoutEnabled const | Returns true if the server idle timer is allowed to reap this connection. |
bool | reusableForPool const | Returns true if the closed connection can be returned to the reuse pool. |
void | markActive virtual inline | Refresh the idle timer. |
void | reset | Reset this connection for reuse with a new socket. Called by the connection pool to avoid allocating a new ServerConnection. |
void | touch inline | Update the last activity timestamp. |
double | idleSeconds const inline | Return seconds since last activity. |
void | beginStreaming virtual | Explicitly mark the response as long-lived streaming. Streaming connections are excluded from the keep-alive idle reaper. |
void | endStreaming virtual | Exit streaming mode and return to the given HTTP state. |
void | endStreaming | |
ssize_t | sendHeader virtual | Send the outgoing HTTP header. |
void | close virtual | Close 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
serverThe owning HTTP server instance.socketThe accepted TCP socket for this connection.
server
Server & server()Returns the owning Server instance.
state
const inline
inline ServerConnectionState state() constReturns the current server-side connection state.
mode
const inline
inline ServerConnectionMode mode() constReturns the current transport mode.
upgraded
const inline
inline bool upgraded() constReturns true if the connection has been upgraded (e.g. to WebSocket).
streaming
const inline
inline bool streaming() constReturns true if the connection is in long-lived streaming mode.
idleTimeoutEnabled
const
bool idleTimeoutEnabled() constReturns true if the server idle timer is allowed to reap this connection.
reusableForPool
const
bool reusableForPool() constReturns 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() constReturn 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
| Return | Name | Description |
|---|---|---|
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
| Return | Name | Description |
|---|---|---|
void | onHeaders virtual | Called when the incoming HTTP headers have been fully parsed. |
void | onPayload virtual | Called for each chunk of incoming body data after headers are complete. |
void | onComplete virtual | Called when the incoming HTTP message is fully received. |
void | onClose virtual | Called when the connection is closed. |
http::Message * | incomingHeader virtual | Returns the incoming HTTP message header (request or response depending on role). |
http::Message * | outgoingHeader virtual | Returns the outgoing HTTP message header (request or response depending on role). |
void | setState | |
bool | requestHasBody const | |
bool | responseLooksStreaming 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
bufferBuffer 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() constresponseLooksStreaming
const
bool responseLooksStreaming() constPublic Types
| Name | Description |
|---|---|
Ptr |
Ptr
std::shared_ptr< ServerConnection > Ptr()