Struct hyper::ffi::hyper_clientconn
source · pub struct hyper_clientconn { /* private fields */ }
ffi
and hyper_unstable_ffi
only.Expand description
An HTTP client connection handle.
These are used to send one or more requests on a single connection.
It’s possible to send multiple requests on a single connection, such as when HTTP/1 keep-alive or HTTP/2 is used.
To create a hyper_clientconn
:
- Create a
hyper_io
withhyper_io_new
. - Create a
hyper_clientconn_options
withhyper_clientconn_options_new
. - Call
hyper_clientconn_handshake
with thehyper_io
andhyper_clientconn_options
. This creates ahyper_task
. - Call
hyper_task_set_userdata
to assign an application-specific pointer to the task. This allows keeping track of multiple connections that may be handshaking simultaneously. - Add the
hyper_task
to an executor withhyper_executor_push
. - Poll that executor until it yields a task of type
HYPER_TASK_CLIENTCONN
. - Extract the
hyper_clientconn
from the task withhyper_task_value
. This will require a cast fromvoid *
tohyper_clientconn *
.
This process results in a hyper_clientconn
that permanently owns the
hyper_io
. Because the hyper_io
in turn owns a TCP or TLS connection, that means
the hyper_clientconn
owns the connection for both the clientconn’s lifetime
and the connection’s lifetime.
In other words, each connection (hyper_io
) must have exactly one hyper_clientconn
associated with it. That’s because hyper_clientconn_handshake
sends the
HTTP/2 Connection Preface (for HTTP/2 connections). Since that preface can’t
be sent twice, handshake can’t be called twice.
Methods:
- hyper_clientconn_handshake: Creates an HTTP client handshake task.
- hyper_clientconn_send: Creates a task to send a request on the client connection.
- hyper_clientconn_free: Free a hyper_clientconn *.