Zephyr API Documentation 4.5.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
http_client_transport_ops Struct Reference

HTTP transport API. More...

#include <zephyr/net/http/client_multiprotocol.h>

Data Fields

bool secure
 Whether the transport is secured with TLS.
void(* init )(void *transport_ctx)
 Initialize transport context.
int(* connect )(struct http_client *client)
 Connect the transport layer.
int(* send )(struct http_client *client, void *stream, const uint8_t *data, size_t len, bool end_stream)
 Send data over the transport layer.
int(* recv )(struct http_client *client, void **stream, uint8_t *buf, size_t bufsize, bool *end_stream)
 Receive data from the transport layer.
int(* wait )(struct http_client *client, k_timeout_t timeout)
 Wait for data to become available.
void(* stop )(struct http_client *client)
 Stop reporting reception events.
int(* close )(struct http_client *client)
 Disconnect the transport layer and release resources.

Detailed Description

HTTP transport API.

Field Documentation

◆ close

int(* http_client_transport_ops::close) (struct http_client *client)

Disconnect the transport layer and release resources.

Called with the client lock released, once the session is closed and nothing is sent any more. A transport with a receive context of its own waits here for a notification already dispatched for the client to return, so that the client can be reinitialized or freed once http_client_disconnect() returns.

Parameters
clientHTTP client instance
Returns
0 on success, a negative errno code otherwise.

◆ connect

int(* http_client_transport_ops::connect) (struct http_client *client)

Connect the transport layer.

The function is expected to establish the connection. For an asynchronous session (http_client_session::async) it also sets up asynchronous reception and calls http_client_received_data() whenever data is available. A synchronous session receives on the calling thread through wait() and recv() instead.

Parameters
clientHTTP client instance
Returns
0 on success, a negative errno code otherwise.

◆ init

void(* http_client_transport_ops::init) (void *transport_ctx)

Initialize transport context.

Parameters
transport_ctxA pointer to the transport context to initialize

◆ recv

int(* http_client_transport_ops::recv) (struct http_client *client, void **stream, uint8_t *buf, size_t bufsize, bool *end_stream)

Receive data from the transport layer.

The function is expected to be non-blocking, returning immediately with whatever data is currently available. If no data is available, the function should return -EAGAIN.

A multi-stream transport receives from the stream requested in stream, or from any stream when NULL is requested, and reports the stream the data came from in the same parameter. It may return -EAGAIN when the requested stream has no data even if other streams do. A single-stream transport ignores the request and reports NULL.

Parameters
clientHTTP client instance
streamTransport stream to receive from on entry, the stream the data came from on return
bufBuffer for the received data
bufsizeSize of the receive buffer
end_streamSet when the peer ended the stream after the returned data. Never set by single-stream transports, which report 0 bytes instead.
Returns
Number of bytes received, 0 if transport was closed by the peer, a negative errno code otherwise.

◆ secure

bool http_client_transport_ops::secure

Whether the transport is secured with TLS.

Selects the URL scheme (http or https) used in requests.

◆ send

int(* http_client_transport_ops::send) (struct http_client *client, void *stream, const uint8_t *data, size_t len, bool end_stream)

Send data over the transport layer.

The function is expected to send all of the data requested, or fail. The sending is always blocking.

Parameters
clientHTTP client instance
streamTransport stream to send on, NULL for the connection itself. A single-stream transport (TCP, TLS) is only ever asked to send on the connection.
dataData to send
lenLength of the data to send
end_streamWhether this is the last data sent on the stream. Ignored by single-stream transports.
Returns
0 on success, a negative errno code otherwise.

◆ stop

void(* http_client_transport_ops::stop) (struct http_client *client)

Stop reporting reception events.

Called when the session ends, before close, which may be left to a thread still sending on the transport. From then on nothing received is read. May be NULL.

Parameters
clientHTTP client instance

◆ wait

int(* http_client_transport_ops::wait) (struct http_client *client, k_timeout_t timeout)

Wait for data to become available.

Used by synchronous sessions, which receive on the calling thread.

Parameters
clientHTTP client instance
timeoutMaximum time to wait
Returns
0 when data is available or the peer closed the transport, -EAGAIN when the timeout expired, a negative errno code on a transport error.

The documentation for this struct was generated from the following file: