Home
HTTP module

ServerConnection

HTTP server connection.

ServerConnection

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

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

Inherits: Connection

HTTP server connection.

List of all members

NameKindOwner
PayloadvariableDeclared here
ClosevariableDeclared here
ServerConnectionfunctionDeclared here
~ServerConnectionfunctionDeclared here
serverfunctionDeclared here
statefunctionDeclared here
modefunctionDeclared here
upgradedfunctionDeclared here
streamingfunctionDeclared here
idleTimeoutEnabledfunctionDeclared here
reusableForPoolfunctionDeclared here
markActivefunctionDeclared here
resetfunctionDeclared here
touchfunctionDeclared here
idleSecondsfunctionDeclared here
beginStreamingfunctionDeclared here
endStreamingfunctionDeclared here
endStreamingfunctionDeclared here
sendHeaderfunctionDeclared here
closefunctionDeclared here
_servervariableDeclared here
_respondervariableDeclared here
_lastActivityvariableDeclared here
_statevariableDeclared here
_modevariableDeclared here
onHeadersfunctionDeclared here
onPayloadfunctionDeclared here
onCompletefunctionDeclared here
onClosefunctionDeclared here
incomingHeaderfunctionDeclared here
outgoingHeaderfunctionDeclared here
setStatefunctionDeclared here
requestHasBodyfunctionDeclared here
responseLooksStreamingfunctionDeclared here
PtrtypedefDeclared here
ConnectionStreamfriendInherited from Connection
ConnectionAdapterfriendInherited from Connection
ConnectionfunctionInherited from Connection
~ConnectionfunctionInherited from Connection
onHeadersfunctionInherited from Connection
onPayloadfunctionInherited from Connection
onCompletefunctionInherited from Connection
onClosefunctionInherited from Connection
sendfunctionInherited from Connection
sendOwnedfunctionInherited from Connection
sendHeaderfunctionInherited from Connection
closefunctionInherited from Connection
markActivefunctionInherited from Connection
beginStreamingfunctionInherited from Connection
endStreamingfunctionInherited from Connection
closedfunctionInherited from Connection
errorfunctionInherited from Connection
headerAutoSendEnabledfunctionInherited from Connection
setHeaderAutoSendEnabledfunctionInherited from Connection
replaceAdapterfunctionInherited from Connection
replaceAdapterfunctionInherited from Connection
securefunctionInherited from Connection
socketfunctionInherited from Connection
adapterfunctionInherited from Connection
requestfunctionInherited from Connection
responsefunctionInherited from Connection
incomingHeaderfunctionInherited from Connection
outgoingHeaderfunctionInherited from Connection
_socketvariableInherited from Connection
_adaptervariableInherited from Connection
_requestvariableInherited from Connection
_responsevariableInherited from Connection
_errorvariableInherited from Connection
_closedvariableInherited from Connection
_shouldSendHeadervariableInherited from Connection
setErrorfunctionInherited from Connection
onSocketConnectfunctionInherited from Connection
onSocketRecvfunctionInherited from Connection
onSocketErrorfunctionInherited from Connection
onSocketClosefunctionInherited from Connection
PtrtypedefInherited from Connection
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 Connection

KindNameDescription
friendConnectionStream
friendConnectionAdapter
functionConnectionCreates a Connection using the given TCP socket.
function~Connection virtual noexcept
functiononHeaders virtualCalled when the incoming HTTP headers have been fully parsed.
functiononPayload virtualCalled for each chunk of incoming body data after headers are complete.
functiononComplete virtualCalled when the incoming HTTP message is fully received.
functiononClose virtualCalled when the connection is closed.
functionsend virtual overrideSend raw data to the peer.
functionsendOwned virtual overrideSend an owned payload buffer to the peer.
functionsendHeader virtualSend the outdoing HTTP header.
functionclose virtualClose the connection and schedule the object for deferred deletion.
functionmarkActive virtual inlineMarks the connection as active. Server connections override this to refresh the idle timer.
functionbeginStreaming virtual inlineExplicitly enter long-lived streaming mode. Base connections ignore this; server connections use it to disable keep-alive idle reaping while a response stream is active.
functionendStreaming virtual inlineExit long-lived streaming mode.
functionclosed constReturn true if the connection is closed.
functionerror constReturn the error object if any.
functionheaderAutoSendEnabled constReturn true if headers should be automatically sent.
functionsetHeaderAutoSendEnabledEnable or disable automatic header emission for the next outgoing send path.
functionreplaceAdapter virtualAssign the new ConnectionAdapter and setup the chain. The flow is: Connection <-> ConnectionAdapter <-> Socket. Takes ownership of the adapter (deferred deletion via uv loop).
functionreplaceAdapter virtualOverload for nullptr (used in destructor to clear adapter).
functionsecure constReturn true if the connection uses TLS/SSL.
functionsocketReturn the underlying socket pointer.
functionadapter constReturn the underlying adapter pointer.
functionrequestThe HTTP request headers.
functionresponseThe HTTP response headers.
functionincomingHeader virtualReturns the incoming HTTP message header (request or response depending on role).
functionoutgoingHeader virtualReturns the outgoing HTTP message header (request or response depending on role).
variable_socket
variable_adapter
variable_request
variable_response
variable_error
variable_closed
variable_shouldSendHeader
functionsetError virtualSet the internal error. Note: Setting the error does not [close()](icy-http-Connection.html#close-27) the connection.
functiononSocketConnect virtual overridenet::SocketAdapter interface
functiononSocketRecv virtual overrideCalled when data is received from the socket. Forwards the event to all registered receivers in priority order.
functiononSocketError virtual overrideCalled when the socket encounters an error. Forwards the event to all registered receivers in priority order.
functiononSocketClose virtual overrideCalled when the socket is closed. Forwards the event to all registered receivers in priority order.
typedefPtr

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

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

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

Signals when raw data is received.


Close

LocalSignal< void(ServerConnection &)> Close

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

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 inline overrideRefresh 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 virtual overrideExplicitly mark the response as long-lived streaming. Streaming connections are excluded from the keep-alive idle reaper.
voidendStreaming virtual overrideExit streaming mode and return to the given HTTP state.
voidendStreaming
ssize_tsendHeader virtual overrideSend the outgoing HTTP header.
voidclose virtual overrideClose the connection with an explicit terminal state transition.

ServerConnection

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

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

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()

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

Returns the owning Server instance.


state

const inline

inline ServerConnectionState state() const

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

Returns the current server-side connection state.


mode

const inline

inline ServerConnectionMode mode() const

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

Returns the current transport mode.


upgraded

const inline

inline bool upgraded() const

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

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


streaming

const inline

inline bool streaming() const

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

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


idleTimeoutEnabled

const

bool idleTimeoutEnabled() const

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

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


reusableForPool

const

bool reusableForPool() const

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

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


markActive

virtual inline override

virtual inline void markActive() override

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

Refresh the idle timer.

Reimplements

reset

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

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

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()

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

Update the last activity timestamp.


idleSeconds

const inline

inline double idleSeconds() const

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

Return seconds since last activity.


beginStreaming

virtual override

virtual void beginStreaming() override

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

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

Reimplements

endStreaming

virtual override

virtual void endStreaming() override

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

Exit streaming mode and return to the given HTTP state.

Reimplements

endStreaming

void endStreaming(ServerConnectionState nextState)

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


sendHeader

virtual override

virtual ssize_t sendHeader() override

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

Send the outgoing HTTP header.

Reimplements

close

virtual override

virtual void close() override

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

Close the connection with an explicit terminal state transition.

Reimplements

Protected Attributes

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

_server

Server & _server

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


_responder

std::unique_ptr< ServerResponder > _responder

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


_lastActivity

std::time_t _lastActivity {0}

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


_state

ServerConnectionState _state {}

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


_mode

ServerConnectionMode _mode {}

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

Protected Methods

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

onHeaders

virtual override

virtual void onHeaders() override

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

Called when the incoming HTTP headers have been fully parsed.

Reimplements

onPayload

virtual override

virtual void onPayload(const MutableBuffer & buffer) override

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

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

Parameters

  • buffer Buffer containing the received data chunk.
Reimplements

onComplete

virtual override

virtual void onComplete() override

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

Called when the incoming HTTP message is fully received.

Reimplements

onClose

virtual override

virtual void onClose() override

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

Called when the connection is closed.

Reimplements

incomingHeader

virtual override

virtual http::Message * incomingHeader() override

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

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

Reimplements

outgoingHeader

virtual override

virtual http::Message * outgoingHeader() override

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

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

Reimplements

setState

void setState(ServerConnectionState state)

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


requestHasBody

const

bool requestHasBody() const

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


responseLooksStreaming

const

bool responseLooksStreaming() const

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

Public Types

NameDescription
Ptr

Ptr

using Ptr = std::shared_ptr< ServerConnection >

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