Home
HTTP module

Connection

Base HTTP connection managing socket I/O and message lifecycle

Connection

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

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

Inherits: SocketAdapter Subclassed by: ClientConnection, ServerConnection

Base HTTP connection managing socket I/O and message lifecycle

List of all members

NameKindOwner
ConnectionStreamfriendDeclared here
ConnectionAdapterfriendDeclared here
ConnectionfunctionDeclared here
~ConnectionfunctionDeclared here
onHeadersfunctionDeclared here
onPayloadfunctionDeclared here
onCompletefunctionDeclared here
onClosefunctionDeclared here
sendfunctionDeclared here
sendOwnedfunctionDeclared here
sendHeaderfunctionDeclared here
closefunctionDeclared here
markActivefunctionDeclared here
beginStreamingfunctionDeclared here
endStreamingfunctionDeclared here
closedfunctionDeclared here
errorfunctionDeclared here
headerAutoSendEnabledfunctionDeclared here
setHeaderAutoSendEnabledfunctionDeclared here
replaceAdapterfunctionDeclared here
replaceAdapterfunctionDeclared here
securefunctionDeclared here
socketfunctionDeclared here
adapterfunctionDeclared here
requestfunctionDeclared here
responsefunctionDeclared here
incomingHeaderfunctionDeclared here
outgoingHeaderfunctionDeclared here
_socketvariableDeclared here
_adaptervariableDeclared here
_requestvariableDeclared here
_responsevariableDeclared here
_errorvariableDeclared here
_closedvariableDeclared here
_shouldSendHeadervariableDeclared here
setErrorfunctionDeclared here
onSocketConnectfunctionDeclared here
onSocketRecvfunctionDeclared here
onSocketErrorfunctionDeclared here
onSocketClosefunctionDeclared here
PtrtypedefDeclared here
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 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

Friends


ConnectionStream

friend class ConnectionStream

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


ConnectionAdapter

friend class ConnectionAdapter

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

Public Methods

ReturnNameDescription
ConnectionCreates a Connection using the given TCP socket.
voidonHeaders virtualCalled when the incoming HTTP headers have been fully parsed.
voidonPayload virtualCalled for each chunk of incoming body data after headers are complete.
voidonComplete virtualCalled when the incoming HTTP message is fully received.
voidonClose virtualCalled when the connection is closed.
ssize_tsend virtual overrideSend raw data to the peer.
ssize_tsendOwned virtual overrideSend an owned payload buffer to the peer.
ssize_tsendHeader virtualSend the outdoing HTTP header.
voidclose virtualClose the connection and schedule the object for deferred deletion.
voidmarkActive virtual inlineMarks the connection as active. Server connections override this to refresh the idle timer.
voidbeginStreaming virtual inlineExplicitly 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.
voidendStreaming virtual inlineExit long-lived streaming mode.
boolclosed constReturn true if the connection is closed.
icy::Errorerror constReturn the error object if any.
boolheaderAutoSendEnabled constReturn true if headers should be automatically sent.
voidsetHeaderAutoSendEnabledEnable or disable automatic header emission for the next outgoing send path.
voidreplaceAdapter virtualAssign the new ConnectionAdapter and setup the chain. The flow is: Connection <-> ConnectionAdapter <-> Socket. Takes ownership of the adapter (deferred deletion via uv loop).
voidreplaceAdapter virtualOverload for nullptr (used in destructor to clear adapter).
boolsecure constReturn true if the connection uses TLS/SSL.
net::TCPSocket::Ptr &socketReturn the underlying socket pointer.
net::SocketAdapter *adapter constReturn the underlying adapter pointer.
Request &requestThe HTTP request headers.
Response &responseThe HTTP response headers.
http::Message *incomingHeader virtualReturns the incoming HTTP message header (request or response depending on role).
http::Message *outgoingHeader virtualReturns 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

  • socket The 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

  • buffer Buffer 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) override

Defined 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) override

Defined 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() const

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

Return true if the connection is closed.


error

const

icy::Error error() const

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

Return the error object if any.


headerAutoSendEnabled

const

bool headerAutoSendEnabled() const

Defined 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() const

Defined 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() const

Defined 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

ReturnNameDescription
net::TCPSocket::Ptr_socket
net::SocketAdapter *_adapter
Request_request
Response_response
icy::Error_error
bool_closed
bool_shouldSendHeader

_socket

net::TCPSocket::Ptr _socket

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


_adapter

net::SocketAdapter * _adapter

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


_request

Request _request

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


_response

Response _response

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


_error

icy::Error _error

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


_closed

bool _closed

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


_shouldSendHeader

bool _shouldSendHeader

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

Protected Methods

ReturnNameDescription
voidsetError virtualSet the internal error. Note: Setting the error does not [close()](#close-27) the connection.
boolonSocketConnect virtual overridenet::SocketAdapter interface
boolonSocketRecv virtual overrideCalled when data is received from the socket. Forwards the event to all registered receivers in priority order.
boolonSocketError virtual overrideCalled when the socket encounters an error. Forwards the event to all registered receivers in priority order.
boolonSocketClose virtual overrideCalled 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) override

Defined 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) override

Defined 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

  • socket The socket that received data.

  • buffer The received data buffer.

  • peerAddress Address 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) override

Defined 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

  • socket The socket that encountered the error.

  • error Error details.

Returns

true to stop propagation to subsequent receivers.

Reimplements
Reimplemented by

onSocketClose

virtual override

virtual bool onSocketClose(net::Socket & socket) override

Defined 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

  • socket The socket that was closed.

Returns

true to stop propagation to subsequent receivers.

Reimplements

Public Types

NameDescription
Ptr

Ptr

using Ptr = std::shared_ptr< Connection >

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