ConnectionAdapter
ConnectionAdapter
#include <icy/http/connection.h>Inherits:
ParserObserver,SocketAdapter
Default HTTP socket adapter for reading and writing HTTP messages
Public Methods
| Return | Name | Description |
|---|---|---|
ConnectionAdapter | Creates a ConnectionAdapter for the given connection. | |
ssize_t | send virtual | Sends data to the peer, flushing the outgoing HTTP header first if needed. |
ssize_t | sendOwned virtual | Sends an owned payload buffer to the connected peer. |
void | removeReceiver | Remove the given receiver. |
Parser & | parser | Returns the HTTP parser instance. |
Connection * | connection | Returns the owning Connection pointer, or nullptr if detached. |
void | reset | 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. |
ConnectionAdapter
ConnectionAdapter(Connection * connection, llhttp_type_t type)Creates a ConnectionAdapter for the given connection.
Parameters
connectionOwning HTTP connection.typeParser type: HTTP_REQUEST for server side, HTTP_RESPONSE for client side.
send
virtual
virtual ssize_t send(const char * data, size_t len, int flags)Sends data to the peer, flushing the outgoing HTTP header first if needed.
Parameters
dataPointer to the data buffer.lenNumber of bytes to send.flagsSend flags (unused for HTTP, used for WebSocket frame type).
Returns
Number of bytes sent, or -1 on error.
sendOwned
virtual
virtual ssize_t sendOwned(Buffer && buffer, int flags)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.
removeReceiver
void removeReceiver(SocketAdapter * adapter)Remove the given receiver.
By default this function does nothing unless the given receiver matches the current receiver.
parser
Parser & parser()Returns the HTTP parser instance.
connection
Connection * connection()Returns the owning Connection pointer, or nullptr if detached.
reset
void reset(net::SocketAdapter * sender, http::Request * request)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
senderNew socket adapter to send data through.requestNew HTTP request object for the parser to populate.
Protected Attributes
| Return | Name | Description |
|---|---|---|
Connection * | _connection | |
Parser | _parser |
_connection
Connection * _connection_parser
Parser _parserProtected Methods
| Return | Name | Description |
|---|---|---|
bool | onSocketRecv virtual | SocketAdapter interface. |
void | onParserHeader virtual | HTTP Parser interface. |
void | onParserHeadersEnd virtual | Called when all HTTP headers have been parsed. |
void | onParserChunk virtual | Called for each chunk of body data received. |
void | onParserError virtual | Called when a parse error occurs. |
void | onParserEnd virtual | Called when the HTTP message is fully parsed. |
onSocketRecv
virtual
virtual bool onSocketRecv(net::Socket & socket, const MutableBuffer & buffer, const net::Address & peerAddress)SocketAdapter interface.
onParserHeader
virtual
virtual void onParserHeader(const std::string & name, const std::string & value)HTTP Parser interface.
onParserHeadersEnd
virtual
virtual void onParserHeadersEnd(bool upgrade)Called when all HTTP headers have been parsed.
Parameters
upgradeTrue if the connection should be upgraded (e.g. to WebSocket).
onParserChunk
virtual
virtual void onParserChunk(const char * data, size_t len)Called for each chunk of body data received.
Parameters
dataPointer to the body data chunk.lenLength of the chunk in bytes.
onParserError
virtual
virtual void onParserError(const icy::Error & err)Called when a parse error occurs.
Parameters
errError details from llhttp.
onParserEnd
virtual
virtual void onParserEnd()Called when the HTTP message is fully parsed.
