Connection
Connection
#include <icy/http/connection.h>class ConnectionDefined in src/http/include/icy/http/connection.h:34
Inherits:
SocketAdapterSubclassed by:ClientConnection,ServerConnection
Base HTTP connection managing socket I/O and message lifecycle
List of all members
| Name | Kind | Owner |
|---|---|---|
ConnectionStream | friend | Declared here |
ConnectionAdapter | friend | Declared here |
Connection | function | Declared here |
~Connection | function | Declared here |
onHeaders | function | Declared here |
onPayload | function | Declared here |
onComplete | function | Declared here |
onClose | function | Declared here |
send | function | Declared here |
sendOwned | function | Declared here |
sendHeader | function | Declared here |
close | function | Declared here |
markActive | function | Declared here |
beginStreaming | function | Declared here |
endStreaming | function | Declared here |
closed | function | Declared here |
error | function | Declared here |
headerAutoSendEnabled | function | Declared here |
setHeaderAutoSendEnabled | function | Declared here |
replaceAdapter | function | Declared here |
replaceAdapter | function | Declared here |
secure | function | Declared here |
socket | function | Declared here |
adapter | function | Declared here |
request | function | Declared here |
response | function | Declared here |
incomingHeader | function | Declared here |
outgoingHeader | function | Declared here |
_socket | variable | Declared here |
_adapter | variable | Declared here |
_request | variable | Declared here |
_response | variable | Declared here |
_error | variable | Declared here |
_closed | variable | Declared here |
_shouldSendHeader | variable | Declared here |
setError | function | Declared here |
onSocketConnect | function | Declared here |
onSocketRecv | function | Declared here |
onSocketError | function | Declared here |
onSocketClose | function | Declared here |
Ptr | typedef | Declared here |
priority | variable | Inherited from SocketAdapter |
SocketAdapter | function | Inherited from SocketAdapter |
~SocketAdapter | function | Inherited from SocketAdapter |
send | function | Inherited from SocketAdapter |
send | function | Inherited from SocketAdapter |
sendOwned | function | Inherited from SocketAdapter |
sendOwned | function | Inherited from SocketAdapter |
sendPacket | function | Inherited from SocketAdapter |
sendPacket | function | Inherited from SocketAdapter |
sendPacket | function | Inherited from SocketAdapter |
setSender | function | Inherited from SocketAdapter |
sender | function | Inherited from SocketAdapter |
addReceiver | function | Inherited from SocketAdapter |
removeReceiver | function | Inherited from SocketAdapter |
hasReceiver | function | Inherited from SocketAdapter |
receivers | function | Inherited from SocketAdapter |
onSocketConnect | function | Inherited from SocketAdapter |
onSocketRecv | function | Inherited from SocketAdapter |
onSocketError | function | Inherited from SocketAdapter |
onSocketClose | function | Inherited from SocketAdapter |
_sender | variable | Inherited from SocketAdapter |
_receivers | variable | Inherited from SocketAdapter |
_dirty | variable | Inherited from SocketAdapter |
cleanupReceivers | function | Inherited from SocketAdapter |
Inherited from SocketAdapter
| Kind | Name | Description |
|---|---|---|
variable | priority | The priority of this adapter for STL sort operations. |
function | SocketAdapter | Creates the SocketAdapter. |
function | ~SocketAdapter virtual noexcept | Destroys the SocketAdapter. |
function | send virtual | Sends 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. |
function | send virtual | |
function | sendOwned virtual | Sends an owned payload buffer to the connected peer. |
function | sendOwned virtual | |
function | sendPacket virtual | Sends 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. |
function | sendPacket virtual | |
function | sendPacket virtual | Sends 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. |
function | setSender virtual | Sets the pointer to the outgoing data adapter. Send methods proxy data to this adapter by default. |
function | sender | Returns the output SocketAdapter pointer. |
function | addReceiver virtual | Sets the pointer to the incoming data adapter. Events proxy data to this adapter by default. |
function | removeReceiver virtual | Remove the given receiver. |
function | hasReceiver virtual | Returns true if the given receiver is connected. |
function | receivers | Returns all currently registered input SocketAdapter pointers. Dead (removed) entries are excluded from the returned list. |
function | onSocketConnect virtual | Called 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. |
function | onSocketRecv virtual | Called when data is received from the socket. Forwards the event to all registered receivers in priority order. |
function | onSocketError virtual | Called when the socket encounters an error. Forwards the event to all registered receivers in priority order. |
function | onSocketClose virtual | Called when the socket is closed. Forwards the event to all registered receivers in priority order. |
variable | _sender | |
variable | _receivers | |
variable | _dirty | |
function | cleanupReceivers virtual |
Friends
| Name | Description |
|---|---|
ConnectionStream | |
ConnectionAdapter |
ConnectionStream
friend class ConnectionStreamDefined in src/http/include/icy/http/connection.h:148
ConnectionAdapter
friend class ConnectionAdapterDefined in src/http/include/icy/http/connection.h:149
Public Methods
| Return | Name | Description |
|---|---|---|
Connection | Creates a Connection using the given TCP socket. | |
void | onHeaders virtual | Called when the incoming HTTP headers have been fully parsed. |
void | onPayload virtual | Called for each chunk of incoming body data after headers are complete. |
void | onComplete virtual | Called when the incoming HTTP message is fully received. |
void | onClose virtual | Called when the connection is closed. |
ssize_t | send virtual override | Send raw data to the peer. |
ssize_t | sendOwned virtual override | 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 virtual | Returns the incoming HTTP message header (request or response depending on role). |
http::Message * | outgoingHeader virtual | Returns the outgoing HTTP message header (request or response depending on role). |
Connection
Connection(const net::TCPSocket::Ptr & socket = std::make_shared< net::TCPSocket >())Defined in src/http/include/icy/http/connection.h:41
Creates a Connection using the given TCP socket.
Parameters
socketThe TCP socket to use for I/O. Defaults to a new TCPSocket.
onHeaders
virtual
virtual void onHeaders()Defined in src/http/include/icy/http/connection.h:45
Called when the incoming HTTP headers have been fully parsed.
Reimplemented by
onPayload
virtual
virtual void onPayload(const MutableBuffer & buffer)Defined in src/http/include/icy/http/connection.h:49
Called for each chunk of incoming body data after headers are complete.
Parameters
bufferBuffer containing the received data chunk.
Reimplemented by
onComplete
virtual
virtual void onComplete()Defined in src/http/include/icy/http/connection.h:52
Called when the incoming HTTP message is fully received.
Reimplemented by
onClose
virtual
virtual void onClose()Defined in src/http/include/icy/http/connection.h:55
Called when the connection is closed.
Reimplemented by
send
virtual override
virtual ssize_t send(const char * data, size_t len, int flags = 0) overrideDefined in src/http/include/icy/http/connection.h:61
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.
Reimplements
Reimplemented by
sendOwned
virtual override
virtual ssize_t sendOwned(Buffer && buffer, int flags = 0) overrideDefined in src/http/include/icy/http/connection.h:66
Send an owned payload buffer to the peer.
Use this when the payload does not naturally outlive the current scope.
Reimplements
sendHeader
virtual
virtual ssize_t sendHeader()Defined in src/http/include/icy/http/connection.h:69
Send the outdoing HTTP header.
Reimplemented by
close
virtual
virtual void close()Defined in src/http/include/icy/http/connection.h:73
Close the connection and schedule the object for deferred deletion.
Reimplemented by
markActive
virtual inline
virtual inline void markActive()Defined in src/http/include/icy/http/connection.h:77
Marks the connection as active. Server connections override this to refresh the idle timer.
Reimplemented by
beginStreaming
virtual inline
virtual inline void beginStreaming()Defined in src/http/include/icy/http/connection.h:82
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.
Reimplemented by
endStreaming
virtual inline
virtual inline void endStreaming()Defined in src/http/include/icy/http/connection.h:85
Exit long-lived streaming mode.
Reimplemented by
closed
const
bool closed() constDefined in src/http/include/icy/http/connection.h:88
Return true if the connection is closed.
error
const
icy::Error error() constDefined in src/http/include/icy/http/connection.h:91
Return the error object if any.
headerAutoSendEnabled
const
bool headerAutoSendEnabled() constDefined in src/http/include/icy/http/connection.h:94
Return true if headers should be automatically sent.
setHeaderAutoSendEnabled
void setHeaderAutoSendEnabled(bool enabled)Defined in src/http/include/icy/http/connection.h:97
Enable or disable automatic header emission for the next outgoing send path.
replaceAdapter
virtual
virtual void replaceAdapter(std::unique_ptr< net::SocketAdapter > adapter)Defined in src/http/include/icy/http/connection.h:102
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)Defined in src/http/include/icy/http/connection.h:105
Overload for nullptr (used in destructor to clear adapter).
secure
const
bool secure() constDefined in src/http/include/icy/http/connection.h:108
Return true if the connection uses TLS/SSL.
socket
net::TCPSocket::Ptr & socket()Defined in src/http/include/icy/http/connection.h:111
Return the underlying socket pointer.
adapter
const
net::SocketAdapter * adapter() constDefined in src/http/include/icy/http/connection.h:114
Return the underlying adapter pointer.
request
Request & request()Defined in src/http/include/icy/http/connection.h:117
The HTTP request headers.
response
Response & response()Defined in src/http/include/icy/http/connection.h:120
The HTTP response headers.
incomingHeader
virtual
virtual http::Message * incomingHeader()Defined in src/http/include/icy/http/connection.h:123
Returns the incoming HTTP message header (request or response depending on role).
Reimplemented by
outgoingHeader
virtual
virtual http::Message * outgoingHeader()Defined in src/http/include/icy/http/connection.h:126
Returns the outgoing HTTP message header (request or response depending on role).
Reimplemented by
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 _socketDefined in src/http/include/icy/http/connection.h:140
_adapter
net::SocketAdapter * _adapterDefined in src/http/include/icy/http/connection.h:141
_request
Request _requestDefined in src/http/include/icy/http/connection.h:142
_response
Response _responseDefined in src/http/include/icy/http/connection.h:143
_error
icy::Error _errorDefined in src/http/include/icy/http/connection.h:144
_closed
bool _closedDefined in src/http/include/icy/http/connection.h:145
_shouldSendHeader
bool _shouldSendHeaderDefined in src/http/include/icy/http/connection.h:146
Protected 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 override | net::SocketAdapter interface |
bool | onSocketRecv virtual override | Called when data is received from the socket. Forwards the event to all registered receivers in priority order. |
bool | onSocketError virtual override | Called when the socket encounters an error. Forwards the event to all registered receivers in priority order. |
bool | onSocketClose virtual override | 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)Defined in src/http/include/icy/http/connection.h:131
Set the internal error. Note: Setting the error does not [close()](#close-27) the connection.
onSocketConnect
virtual override
virtual bool onSocketConnect(net::Socket & socket) overrideDefined in src/http/include/icy/http/connection.h:134
net::SocketAdapter interface
Reimplements
Reimplemented by
onSocketRecv
virtual override
virtual bool onSocketRecv(net::Socket & socket, const MutableBuffer & buffer, const net::Address & peerAddress) overrideDefined in src/http/include/icy/http/connection.h:135
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.
Reimplements
onSocketError
virtual override
virtual bool onSocketError(net::Socket & socket, const icy::Error & error) overrideDefined in src/http/include/icy/http/connection.h:136
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.
Reimplements
Reimplemented by
onSocketClose
virtual override
virtual bool onSocketClose(net::Socket & socket) overrideDefined in src/http/include/icy/http/connection.h:137
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.
Reimplements
Public Types
| Name | Description |
|---|---|
Ptr |
Ptr
using Ptr = std::shared_ptr< Connection >