Connection
Connection
#include <icy/http/connection.h>Inherits:
SocketAdapterSubclassed by:ClientConnection,ServerConnection
Base HTTP connection managing socket I/O and message lifecycle
Public Methods
| 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
Connection(const net::TCPSocket::Ptr & socket)Creates a Connection using the given TCP socket.
Parameters
socketThe TCP socket to use for I/O. Defaults to a new TCPSocket.
onHeaders
void onHeaders()Called when the incoming HTTP headers have been fully parsed.
onPayload
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
void onComplete()Called when the incoming HTTP message is fully received.
onClose
void onClose()Called when the connection is closed.
send
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.
sendOwned
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.
sendHeader
virtual
virtual ssize_t sendHeader()Send the outdoing HTTP header.
close
virtual
virtual void close()Close the connection and schedule the object for deferred deletion.
markActive
virtual inline
virtual inline void markActive()Marks the connection as active. Server connections override this to refresh the idle timer.
beginStreaming
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.
endStreaming
virtual inline
virtual inline void endStreaming()Exit long-lived streaming mode.
closed
const
bool closed() constReturn true if the connection is closed.
error
const
icy::Error error() constReturn the error object if any.
headerAutoSendEnabled
const
bool headerAutoSendEnabled() constReturn true if headers should be automatically sent.
setHeaderAutoSendEnabled
void setHeaderAutoSendEnabled(bool enabled)Enable or disable automatic header emission for the next outgoing send path.
replaceAdapter
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).
replaceAdapter
virtual
virtual void replaceAdapter(std::nullptr_t)Overload for nullptr (used in destructor to clear adapter).
secure
const
bool secure() constReturn true if the connection uses TLS/SSL.
socket
net::TCPSocket::Ptr & socket()Return the underlying socket pointer.
adapter
const
net::SocketAdapter * adapter() constReturn the underlying adapter pointer.
request
Request & request()The HTTP request headers.
response
Response & response()The HTTP response headers.
incomingHeader
http::Message * incomingHeader()Returns the incoming HTTP message header (request or response depending on role).
outgoingHeader
http::Message * outgoingHeader()Returns the outgoing HTTP message header (request or response depending on role).
Protected Attributes
| Return | Name | Description |
|---|---|---|
net::TCPSocket::Ptr | _socket | |
net::SocketAdapter * | _adapter | |
Request | _request | |
Response | _response | |
icy::Error | _error | |
bool | _closed | |
bool | _shouldSendHeader |
_socket
net::TCPSocket::Ptr _socket_adapter
net::SocketAdapter * _adapter_request
Request _request_response
Response _response_error
icy::Error _error_closed
bool _closed_shouldSendHeader
bool _shouldSendHeaderProtected Methods
| 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. |
setError
virtual
virtual void setError(const icy::Error & err)Set the internal error. Note: Setting the error does not [close()](#close-27) the connection.
onSocketConnect
virtual
virtual bool onSocketConnect(net::Socket & socket)net::SocketAdapter interface
onSocketRecv
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.
Parameters
socketThe socket that received data.bufferThe received data buffer.peerAddressAddress of the sender.
Returns
true to stop propagation to subsequent receivers.
onSocketError
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.
Parameters
socketThe socket that encountered the error.errorError details.
Returns
true to stop propagation to subsequent receivers.
onSocketClose
virtual
virtual bool onSocketClose(net::Socket & socket)Called when the socket is closed. Forwards the event to all registered receivers in priority order.
Parameters
socketThe socket that was closed.
Returns
true to stop propagation to subsequent receivers.
Public Types
| Name | Description |
|---|---|
Ptr |
Ptr
std::shared_ptr< Connection > Ptr()