Picoquic is designed to limit the number of memory copies and related memory allocations when sending and receiving data.
Application data is sent as either data frames or stream frames. The sending process will format packets, send them, and also keep them in memory for possible repetitions.
The typical flow would be:
picoquic_add_to_stream
which allocates memory and keep a copy, or by signalling that data is available on a stream
using picoquic_mark_active_stream
, or by signalling that datagrams are ready to send
using picoquic_mark_datagram_ready
.picoquic_prepare_next_packet_ex
to ask the stack to prepare the next packet in the QUIC context. It provides
a data buffer in which the packet will be copied before being sent.picoquic_prepare_packet_ex
to prepare the next packet for that connection.picoquic_packet_t
, which will
contain the formatted packet.picoquic_add_to_stream
API, or copied directly from the application
memory using a callback picoquic_callback_prepare_to_send
for streams, or
picoquic_callback_prepare_datagram
for datagrams.packet
structure
is left untouched, and the encrypted bytes are copied into the “send” buffer
passed in picoquic_prepare_next_packet_ex
call. That buffer will be sent to
the peer through a socket call.In most cases, the clear text packet will be detached from the retransmission queue when the acknowledgement is received. In some cases, the acknowledgement is not received, and the data will have to be resent. For stream data, this will involve copying the stream data from the old copy into a new packet.
When packets are acknowledged, the picoquic_packet_t
element is “recycled”. It is added
to a queue of empty packets managed in the Quic context, unless that queue has already
reached its maximum size, in which case the packets are freed. New packet structures are
only allocated when no recycled packet is available.
The picoquic stack receives encrypted packets from the network, and delivers decrypted data to the application.
The typical flow would be:
picoquic_incoming_packet
.picoquic_stream_data_node_t
.picoquic_callback_datagram
. The processing of stream data frames varies,
because stream data must be delivered in order.picoquic_callback_stream_data
or picoquic_callback_stream_fin
.When stream data frames arrive out of order, one data node is queued for
each incoming frame. When a hole filling frame arrives, the data is delivered
through the callback picoquic_callback_stream_data
and the data node
is recycled. The data nodes will also be recycled if the stream is reset
or the connection is closed.