Home
HTTP module

ConnectionAdapter

Default HTTP socket adapter for reading and writing HTTP messages

ConnectionAdapter

#include <icy/http/connection.h>
class ConnectionAdapter

Defined in src/http/include/icy/http/connection.h:160

Inherits: ParserObserver, SocketAdapter

Default HTTP socket adapter for reading and writing HTTP messages

List of all members

NameKindOwner
ConnectionAdapterfunctionDeclared here
~ConnectionAdapterfunctionDeclared here
sendfunctionDeclared here
sendOwnedfunctionDeclared here
removeReceiverfunctionDeclared here
parserfunctionDeclared here
connectionfunctionDeclared here
resetfunctionDeclared here
_connectionvariableDeclared here
_parservariableDeclared here
onSocketRecvfunctionDeclared here
onParserHeaderfunctionDeclared here
onParserHeadersEndfunctionDeclared here
onParserChunkfunctionDeclared here
onParserErrorfunctionDeclared here
onParserEndfunctionDeclared here
onParserHeaderfunctionInherited from ParserObserver
onParserHeadersEndfunctionInherited from ParserObserver
onParserChunkfunctionInherited from ParserObserver
onParserEndfunctionInherited from ParserObserver
onParserErrorfunctionInherited from ParserObserver
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 ParserObserver

KindNameDescription
functiononParserHeader virtualCalled for each parsed HTTP header name/value pair.
functiononParserHeadersEnd virtualCalled when all HTTP headers have been parsed.
functiononParserChunk virtualCalled for each chunk of body data received.
functiononParserEnd virtualCalled when the HTTP message is fully parsed.
functiononParserError virtualCalled when a parse error occurs.

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 Methods

ReturnNameDescription
ConnectionAdapterCreates a ConnectionAdapter for the given connection.
ssize_tsend virtual overrideSends data to the peer, flushing the outgoing HTTP header first if needed.
ssize_tsendOwned virtual overrideSends an owned payload buffer to the connected peer.
voidremoveReceiver overrideRemove the given receiver.
Parser &parserReturns the HTTP parser instance.
Connection *connectionReturns the owning Connection pointer, or nullptr if detached.
voidresetResets the adapter for reuse with a new socket and request. Clears the parser state and re-wires the sender without reallocating. Used by the connection pool to avoid destroying/recreating adapters.

ConnectionAdapter

ConnectionAdapter(Connection * connection, llhttp_type_t type)

Defined in src/http/include/icy/http/connection.h:167

Creates a ConnectionAdapter for the given connection.

Parameters

  • connection Owning HTTP connection.

  • type Parser type: HTTP_REQUEST for server side, HTTP_RESPONSE for client side.


send

virtual override

virtual ssize_t send(const char * data, size_t len, int flags = 0) override

Defined in src/http/include/icy/http/connection.h:175

Sends data to the peer, flushing the outgoing HTTP header first if needed.

Parameters

  • data Pointer to the data buffer.

  • len Number of bytes to send.

  • flags Send flags (unused for HTTP, used for WebSocket frame type).

Returns

Number of bytes sent, or -1 on error.

Reimplements

sendOwned

virtual override

virtual ssize_t sendOwned(Buffer && buffer, int flags = 0) override

Defined in src/http/include/icy/http/connection.h:176

Sends an owned payload buffer to the connected peer.

The buffer is moved through the adapter chain and retained by the transport layer until async write completion.

Reimplements

removeReceiver

override

void removeReceiver(SocketAdapter * adapter) override

Defined in src/http/include/icy/http/connection.h:182

Remove the given receiver.

By default this function does nothing unless the given receiver matches the current receiver.


parser

Parser & parser()

Defined in src/http/include/icy/http/connection.h:185

Returns the HTTP parser instance.


connection

Connection * connection()

Defined in src/http/include/icy/http/connection.h:188

Returns the owning Connection pointer, or nullptr if detached.


reset

void reset(net::SocketAdapter * sender, http::Request * request)

Defined in src/http/include/icy/http/connection.h:195

Resets the adapter for reuse with a new socket and request. Clears the parser state and re-wires the sender without reallocating. Used by the connection pool to avoid destroying/recreating adapters.

Parameters

  • sender New socket adapter to send data through.

  • request New HTTP request object for the parser to populate.

Protected Attributes

ReturnNameDescription
Connection *_connection
Parser_parser

_connection

Connection * _connection

Defined in src/http/include/icy/http/connection.h:208


_parser

Parser _parser

Defined in src/http/include/icy/http/connection.h:209

Protected Methods

ReturnNameDescription
boolonSocketRecv virtual overrideSocketAdapter interface.
voidonParserHeader virtual overrideHTTP Parser interface.
voidonParserHeadersEnd virtual overrideCalled when all HTTP headers have been parsed.
voidonParserChunk virtual overrideCalled for each chunk of body data received.
voidonParserError virtual overrideCalled when a parse error occurs.
voidonParserEnd virtual overrideCalled when the HTTP message is fully parsed.

onSocketRecv

virtual override

virtual bool onSocketRecv(net::Socket & socket, const MutableBuffer & buffer, const net::Address & peerAddress) override

Defined in src/http/include/icy/http/connection.h:199

SocketAdapter interface.

Reimplements

onParserHeader

virtual override

virtual void onParserHeader(const std::string & name, const std::string & value) override

Defined in src/http/include/icy/http/connection.h:202

HTTP Parser interface.

Reimplements

onParserHeadersEnd

virtual override

virtual void onParserHeadersEnd(bool upgrade) override

Defined in src/http/include/icy/http/connection.h:203

Called when all HTTP headers have been parsed.

Parameters

  • upgrade True if the connection should be upgraded (e.g. to WebSocket).
Reimplements

onParserChunk

virtual override

virtual void onParserChunk(const char * data, size_t len) override

Defined in src/http/include/icy/http/connection.h:204

Called for each chunk of body data received.

Parameters

  • data Pointer to the body data chunk.

  • len Length of the chunk in bytes.

Reimplements

onParserError

virtual override

virtual void onParserError(const icy::Error & err) override

Defined in src/http/include/icy/http/connection.h:205

Called when a parse error occurs.

Parameters

  • err Error details from llhttp.
Reimplements

onParserEnd

virtual override

virtual void onParserEnd() override

Defined in src/http/include/icy/http/connection.h:206

Called when the HTTP message is fully parsed.

Reimplements