#include <icy/http/connection.h>Inherits:
SocketAdapterSubclassed by:ClientConnection,ServerConnection
Base HTTP connection managing socket I/O and message lifecycle
| Return | Name | Description |
|---|---|---|
Connection | Creates a Connection using the given TCP socket. | |
void | onHeaders | Called when the incoming HTTP headers have been fully parsed. |
void | onPayload | Called for each chunk of incoming body data after headers are complete. |
void | onComplete | Called when the incoming HTTP message is fully received. |
void | onClose | Called when the connection is closed. |
ssize_t | send virtual | Send raw data to the peer. |
ssize_t | sendOwned virtual | Send an owned payload buffer to the peer. |
ssize_t | sendHeader virtual | Send the outdoing HTTP header. |
void | close virtual | Close the connection and schedule the object for deferred deletion. |
void | markActive virtual inline | Marks the connection as active. Server connections override this to refresh the idle timer. |
void | beginStreaming virtual inline | Explicitly 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. |
void | endStreaming virtual inline | Exit long-lived streaming mode. |
bool | closed const | Return true if the connection is closed. |
icy::Error | error const | Return the error object if any. |
bool | headerAutoSendEnabled const | Return true if headers should be automatically sent. |
void | setHeaderAutoSendEnabled | Enable or disable automatic header emission for the next outgoing send path. |
void | replaceAdapter virtual | Assign the new ConnectionAdapter and setup the chain. The flow is: Connection <-> ConnectionAdapter <-> Socket. Takes ownership of the adapter (deferred deletion via uv loop). |
void | replaceAdapter virtual | Overload for nullptr (used in destructor to clear adapter). |
bool | secure const | Return true if the connection uses TLS/SSL. |
net::TCPSocket::Ptr & | socket | Return the underlying socket pointer. |
net::SocketAdapter * | adapter const | Return the underlying adapter pointer. |
Request & | request | The HTTP request headers. |
Response & | response | The HTTP response headers. |
http::Message * | incomingHeader | Returns the incoming HTTP message header (request or response depending on role). |
http::Message * | outgoingHeader | Returns the outgoing HTTP message header (request or response depending on role). |
Connection(const net::TCPSocket::Ptr & socket)Creates a Connection using the given TCP socket.
socket The TCP socket to use for I/O. Defaults to a new TCPSocket.void onHeaders()Called when the incoming HTTP headers have been fully parsed.
void onPayload(const MutableBuffer & buffer)Called for each chunk of incoming body data after headers are complete.
buffer Buffer containing the received data chunk.void onComplete()Called when the incoming HTTP message is fully received.
void onClose()Called when the connection is closed.
virtual
virtual ssize_t send(const char * data, size_t len, int flags)Send raw data to the peer.
This is the zero-copy fast path. The caller retains ownership of the payload until the underlying async write completes.
virtual
virtual ssize_t sendOwned(Buffer && buffer, int flags)Send an owned payload buffer to the peer.
Use this when the payload does not naturally outlive the current scope.
virtual
virtual ssize_t sendHeader()Send the outdoing HTTP header.
virtual
virtual void close()Close the connection and schedule the object for deferred deletion.
virtual inline
virtual inline void markActive()Marks the connection as active. Server connections override this to refresh the idle timer.
virtual inline
virtual inline void beginStreaming()Explicitly 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.
virtual inline
virtual inline void endStreaming()Exit long-lived streaming mode.
const
bool closed() constReturn true if the connection is closed.
const
icy::Error error() constReturn the error object if any.
const
bool headerAutoSendEnabled() constReturn true if headers should be automatically sent.
void setHeaderAutoSendEnabled(bool enabled)Enable or disable automatic header emission for the next outgoing send path.
virtual
virtual void replaceAdapter(std::unique_ptr< net::SocketAdapter > adapter)Assign the new ConnectionAdapter and setup the chain. The flow is: Connection <-> ConnectionAdapter <-> Socket. Takes ownership of the adapter (deferred deletion via uv loop).
virtual
virtual void replaceAdapter(std::nullptr_t)Overload for nullptr (used in destructor to clear adapter).
const
bool secure() constReturn true if the connection uses TLS/SSL.
net::TCPSocket::Ptr & socket()Return the underlying socket pointer.
const
net::SocketAdapter * adapter() constReturn the underlying adapter pointer.
Request & request()The HTTP request headers.
Response & response()The HTTP response headers.
http::Message * incomingHeader()Returns the incoming HTTP message header (request or response depending on role).
http::Message * outgoingHeader()Returns the outgoing HTTP message header (request or response depending on role).
| Return | Name | Description |
|---|---|---|
net::TCPSocket::Ptr | _socket | |
net::SocketAdapter * | _adapter | |
Request | _request | |
Response | _response | |
icy::Error | _error | |
bool | _closed | |
bool | _shouldSendHeader |
net::TCPSocket::Ptr _socketnet::SocketAdapter * _adapterRequest _requestResponse _responseicy::Error _errorbool _closedbool _shouldSendHeader| Return | Name | Description |
|---|---|---|
void | setError virtual | Set the internal error. Note: Setting the error does not [close()](#close-27) the connection. |
bool | onSocketConnect virtual | net::SocketAdapter interface |
bool | onSocketRecv virtual | Called when data is received from the socket. Forwards the event to all registered receivers in priority order. |
bool | onSocketError virtual | Called when the socket encounters an error. Forwards the event to all registered receivers in priority order. |
bool | onSocketClose virtual | Called when the socket is closed. Forwards the event to all registered receivers in priority order. |
virtual
virtual void setError(const icy::Error & err)Set the internal error. Note: Setting the error does not [close()](#close-27) the connection.
virtual
virtual bool onSocketConnect(net::Socket & socket)net::SocketAdapter interface
virtual
virtual bool onSocketRecv(net::Socket & socket, const MutableBuffer & buffer, const net::Address & peerAddress)Called when data is received from the socket. Forwards the event to all registered receivers in priority order.
socket The socket that received data.
buffer The received data buffer.
peerAddress Address of the sender.
true to stop propagation to subsequent receivers.
virtual
virtual bool onSocketError(net::Socket & socket, const icy::Error & error)Called when the socket encounters an error. Forwards the event to all registered receivers in priority order.
socket The socket that encountered the error.
error Error details.
true to stop propagation to subsequent receivers.
virtual
virtual bool onSocketClose(net::Socket & socket)Called when the socket is closed. Forwards the event to all registered receivers in priority order.
socket The socket that was closed.true to stop propagation to subsequent receivers.
| Name | Description |
|---|---|
Ptr |
std::shared_ptr< Connection > Ptr()