ClientConnection
ClientConnection
#include <icy/http/client.h>class ClientConnectionDefined in src/http/include/icy/http/client.h:33
Inherits:
Connection
HTTP client connection for managing request/response lifecycle.
List of all members
| Name | Kind | Owner |
|---|---|---|
opaque | variable | Declared here |
Connect | variable | Declared here |
Headers | variable | Declared here |
Payload | variable | Declared here |
Complete | variable | Declared here |
Error | variable | Declared here |
Close | variable | Declared here |
IncomingProgress | variable | Declared here |
ClientConnection | function | Declared here |
~ClientConnection | function | Declared here |
start | function | Declared here |
start | function | Declared here |
send | function | Declared here |
setReadStream | function | Declared here |
readStream | function | Declared here |
_url | variable | Declared here |
_connect | variable | Declared here |
_active | variable | Declared here |
_complete | variable | Declared here |
_outgoingBuffer | variable | Declared here |
_readStream | variable | Declared here |
connect | function | Declared here |
incomingHeader | function | Declared here |
outgoingHeader | function | Declared here |
onSocketConnect | function | Declared here |
Ptr | typedef | Declared here |
onHeaders | function | Declared here |
onPayload | function | Declared here |
onComplete | function | Declared here |
onClose | function | Declared here |
onSocketError | function | Declared here |
ConnectionStream | friend | Inherited from Connection |
ConnectionAdapter | friend | Inherited from Connection |
Connection | function | Inherited from Connection |
~Connection | function | Inherited from Connection |
onHeaders | function | Inherited from Connection |
onPayload | function | Inherited from Connection |
onComplete | function | Inherited from Connection |
onClose | function | Inherited from Connection |
send | function | Inherited from Connection |
sendOwned | function | Inherited from Connection |
sendHeader | function | Inherited from Connection |
close | function | Inherited from Connection |
markActive | function | Inherited from Connection |
beginStreaming | function | Inherited from Connection |
endStreaming | function | Inherited from Connection |
closed | function | Inherited from Connection |
error | function | Inherited from Connection |
headerAutoSendEnabled | function | Inherited from Connection |
setHeaderAutoSendEnabled | function | Inherited from Connection |
replaceAdapter | function | Inherited from Connection |
replaceAdapter | function | Inherited from Connection |
secure | function | Inherited from Connection |
socket | function | Inherited from Connection |
adapter | function | Inherited from Connection |
request | function | Inherited from Connection |
response | function | Inherited from Connection |
incomingHeader | function | Inherited from Connection |
outgoingHeader | function | Inherited from Connection |
_socket | variable | Inherited from Connection |
_adapter | variable | Inherited from Connection |
_request | variable | Inherited from Connection |
_response | variable | Inherited from Connection |
_error | variable | Inherited from Connection |
_closed | variable | Inherited from Connection |
_shouldSendHeader | variable | Inherited from Connection |
setError | function | Inherited from Connection |
onSocketConnect | function | Inherited from Connection |
onSocketRecv | function | Inherited from Connection |
onSocketError | function | Inherited from Connection |
onSocketClose | function | Inherited from Connection |
Ptr | typedef | Inherited from Connection |
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 Connection
| Kind | Name | Description |
|---|---|---|
friend | ConnectionStream | |
friend | ConnectionAdapter | |
function | Connection | Creates a Connection using the given TCP socket. |
function | ~Connection virtual noexcept | |
function | onHeaders virtual | Called when the incoming HTTP headers have been fully parsed. |
function | onPayload virtual | Called for each chunk of incoming body data after headers are complete. |
function | onComplete virtual | Called when the incoming HTTP message is fully received. |
function | onClose virtual | Called when the connection is closed. |
function | send virtual override | Send raw data to the peer. |
function | sendOwned virtual override | Send an owned payload buffer to the peer. |
function | sendHeader virtual | Send the outdoing HTTP header. |
function | close virtual | Close the connection and schedule the object for deferred deletion. |
function | markActive virtual inline | Marks the connection as active. Server connections override this to refresh the idle timer. |
function | 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. |
function | endStreaming virtual inline | Exit long-lived streaming mode. |
function | closed const | Return true if the connection is closed. |
function | error const | Return the error object if any. |
function | headerAutoSendEnabled const | Return true if headers should be automatically sent. |
function | setHeaderAutoSendEnabled | Enable or disable automatic header emission for the next outgoing send path. |
function | 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). |
function | replaceAdapter virtual | Overload for nullptr (used in destructor to clear adapter). |
function | secure const | Return true if the connection uses TLS/SSL. |
function | socket | Return the underlying socket pointer. |
function | adapter const | Return the underlying adapter pointer. |
function | request | The HTTP request headers. |
function | response | The HTTP response headers. |
function | incomingHeader virtual | Returns the incoming HTTP message header (request or response depending on role). |
function | outgoingHeader virtual | Returns the outgoing HTTP message header (request or response depending on role). |
variable | _socket | |
variable | _adapter | |
variable | _request | |
variable | _response | |
variable | _error | |
variable | _closed | |
variable | _shouldSendHeader | |
function | setError virtual | Set the internal error. Note: Setting the error does not [close()](icy-http-Connection.html#close-27) the connection. |
function | onSocketConnect virtual override | net::SocketAdapter interface |
function | onSocketRecv virtual override | Called when data is received from the socket. Forwards the event to all registered receivers in priority order. |
function | onSocketError virtual override | Called when the socket encounters an error. Forwards the event to all registered receivers in priority order. |
function | onSocketClose virtual override | Called when the socket is closed. Forwards the event to all registered receivers in priority order. |
typedef | Ptr |
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 |
Public Attributes
| Return | Name | Description |
|---|---|---|
void * | opaque | Optional unmanaged client data pointer. Not used by the connection internally. |
NullSignal | Connect | Status signals. |
Signal< void(Response &)> | Headers | Signals when the response HTTP header has been received. |
Signal< void(const MutableBuffer &)> | Payload | Signals when raw data is received. |
Signal< void(const Response &)> | Complete | Signals when the HTTP transaction is complete. |
Signal< void(const icy::Error &)> | Error | Signals when the underlying transport reports an error. |
Signal< void(Connection &)> | Close | Signals when the connection is closed. |
ProgressSignal | IncomingProgress | Signals download progress (0-100%) |
opaque
void * opaqueDefined in src/http/include/icy/http/client.h:91
Optional unmanaged client data pointer. Not used by the connection internally.
Connect
NullSignal ConnectDefined in src/http/include/icy/http/client.h:110
Status signals.
Signals when the client socket is connected and data can flow
Headers
Signal< void(Response &)> HeadersDefined in src/http/include/icy/http/client.h:111
Signals when the response HTTP header has been received.
Payload
Signal< void(const MutableBuffer &)> PayloadDefined in src/http/include/icy/http/client.h:112
Signals when raw data is received.
Complete
Signal< void(const Response &)> CompleteDefined in src/http/include/icy/http/client.h:113
Signals when the HTTP transaction is complete.
Error
Signal< void(const icy::Error &)> ErrorDefined in src/http/include/icy/http/client.h:114
Signals when the underlying transport reports an error.
Close
Signal< void(Connection &)> CloseDefined in src/http/include/icy/http/client.h:115
Signals when the connection is closed.
IncomingProgress
ProgressSignal IncomingProgressDefined in src/http/include/icy/http/client.h:116
Signals download progress (0-100%)
Public Methods
| Return | Name | Description |
|---|---|---|
ClientConnection | Creates a ClientConnection to the given URL, pre-populating the request URI and Host header. The response status is initialised to 502 Bad Gateway until a real response is received. | |
void | start virtual | Starts the internal HTTP request. |
void | start virtual | Starts the given HTTP request, replacing the internal request object. |
ssize_t | send virtual override | Sends raw data to the peer, initiating a connection first if needed. Data is buffered internally until the connection is established. |
void | setReadStream virtual | Sets the output stream to which incoming response body data is written. The stream pointer is owned by the connection and freed with it. Must be called before start(). |
StreamT & | readStream inline | Returns a reference to the read stream cast to the specified type. |
ClientConnection
ClientConnection(const URL & url, const net::TCPSocket::Ptr & socket = std::make_shared< net::TCPSocket >())Defined in src/http/include/icy/http/client.h:42
Creates a ClientConnection to the given URL, pre-populating the request URI and Host header. The response status is initialised to 502 Bad Gateway until a real response is received.
Parameters
urlTarget URL. Scheme, host, port and path are extracted automatically.socketTCP socket to use. Defaults to a plain TCPSocket; pass an SSLSocket for HTTPS.
start
virtual
virtual void start()Defined in src/http/include/icy/http/client.h:51
Starts the internal HTTP request.
Calls connect() internally if the socket is not already connecting or connected. The actual request will be sent when the socket is connected.
Exceptions
std::runtime_errorif already connecting.
start
virtual
virtual void start(http::Request & req)Defined in src/http/include/icy/http/client.h:59
Starts the given HTTP request, replacing the internal request object.
Calls connect() internally if the socket is not already connecting or connected. The actual request will be sent when the socket is connected.
Parameters
reqThe HTTP request to send. Replaces the internal request.
Exceptions
std::runtime_errorif already connecting.
send
virtual override
virtual ssize_t send(const char * data, size_t len, int flags = 0) overrideDefined in src/http/include/icy/http/client.h:67
Sends raw data to the peer, initiating a connection first if needed. Data is buffered internally until the connection is established.
Parameters
dataPointer to the data buffer.lenNumber of bytes to send.flagsSocket send flags (unused for HTTP).
Returns
Number of bytes sent or buffered.
Reimplements
setReadStream
virtual
virtual void setReadStream(std::ostream * os)Defined in src/http/include/icy/http/client.h:74
Sets the output stream to which incoming response body data is written. The stream pointer is owned by the connection and freed with it. Must be called before start().
Parameters
osPointer to the output stream. Takes ownership.
Exceptions
std::runtime_errorif already connecting.
readStream
inline
template<class StreamT> inline StreamT & readStream()Defined in src/http/include/icy/http/client.h:82
Returns a reference to the read stream cast to the specified type.
Parameters
StreamTThe concrete stream type to cast to.
Returns
Reference to the stream.
Exceptions
std::runtime_errorif no read stream has been set.std::bad_castif the stream is not of type StreamT.
Protected Attributes
| Return | Name | Description |
|---|---|---|
URL | _url | |
bool | _connect | |
bool | _active | |
bool | _complete | |
std::vector< PendingWrite > | _outgoingBuffer | |
std::unique_ptr< std::ostream > | _readStream |
_url
URL _urlDefined in src/http/include/icy/http/client.h:135
_connect
bool _connectDefined in src/http/include/icy/http/client.h:136
_active
bool _activeDefined in src/http/include/icy/http/client.h:137
_complete
bool _completeDefined in src/http/include/icy/http/client.h:138
_outgoingBuffer
std::vector< PendingWrite > _outgoingBufferDefined in src/http/include/icy/http/client.h:139
_readStream
std::unique_ptr< std::ostream > _readStreamDefined in src/http/include/icy/http/client.h:140
Protected Methods
| Return | Name | Description |
|---|---|---|
void | connect virtual | Connects to the server endpoint. All sent data is buffered until the connection is made. |
http::Message * | incomingHeader virtual override | Returns the incoming HTTP message header (request or response depending on role). |
http::Message * | outgoingHeader virtual override | Returns the outgoing HTTP message header (request or response depending on role). |
bool | onSocketConnect virtual override | net::SocketAdapter interface |
connect
virtual
virtual void connect()Defined in src/http/include/icy/http/client.h:121
Connects to the server endpoint. All sent data is buffered until the connection is made.
incomingHeader
virtual override
virtual http::Message * incomingHeader() overrideDefined in src/http/include/icy/http/client.h:123
Returns the incoming HTTP message header (request or response depending on role).
Reimplements
outgoingHeader
virtual override
virtual http::Message * outgoingHeader() overrideDefined in src/http/include/icy/http/client.h:124
Returns the outgoing HTTP message header (request or response depending on role).
Reimplements
onSocketConnect
virtual override
virtual bool onSocketConnect(net::Socket & socket) overrideDefined in src/http/include/icy/http/client.h:126
net::SocketAdapter interface
Reimplements
Public Types
| Name | Description |
|---|---|
Ptr |
Ptr
using Ptr = std::shared_ptr< ClientConnection >Defined in src/http/include/icy/http/client.h:36
Private Methods
| Return | Name | Description |
|---|---|---|
void | onHeaders virtual override | Connection interface. |
void | onPayload virtual override | Called for each chunk of incoming response body data. |
void | onComplete virtual override | Called when the full HTTP response has been received. |
void | onClose virtual override | Called when the connection is closed. |
bool | onSocketError virtual override | Called when the underlying transport encounters an error. |
onHeaders
virtual override
virtual void onHeaders() overrideDefined in src/http/include/icy/http/client.h:97
Connection interface.
Called when the response headers have been parsed.
Reimplements
onPayload
virtual override
virtual void onPayload(const MutableBuffer & buffer) overrideDefined in src/http/include/icy/http/client.h:99
Called for each chunk of incoming response body data.
Reimplements
onComplete
virtual override
virtual void onComplete() overrideDefined in src/http/include/icy/http/client.h:101
Called when the full HTTP response has been received.
Reimplements
onClose
virtual override
virtual void onClose() overrideDefined in src/http/include/icy/http/client.h:103
Called when the connection is closed.
Reimplements
onSocketError
virtual override
virtual bool onSocketError(net::Socket & socket, const icy::Error & error) overrideDefined in src/http/include/icy/http/client.h:105
Called when the underlying transport encounters an error.
