C Collections

cthreadcomm · Section 3

ccircq_timed_send

ccircq_timed_send - send a message with a timeout

C Collections (libccollections, -lccollections)

#include <ccollections/cthreadcomm.h>
 
ccol_retval ccircq_timed_send(ccircq *cq,
                                cmessage *msg,
                                uint64_t timeout_us);

Works like ccircq_send(), but waits for free space for at most
timeout_us microseconds. When the timeout ends, or sends are turned
off while it waits, the call returns the matching error code.

cq          Circular queue to send to
msg         Message to send. On success the ownership of the data moves to
            the queue.
timeout_us  Longest time to wait, in microseconds, from the call. 0
            does not wait, which makes the call ccircq_try_send.

ccol_success              - The message was sent
ccol_invalid_args         - cq or msg is NULL, msg->data is NULL
                            while msg->size is not 0, or msg->data
                            is not NULL while msg->size is 0
ccol_not_permitted        - Sends on the queue are turned off
ccol_container_full       - The timeout is 0 and the queue is full
ccol_timed_out            - The timeout ended
ccol_unexpected_failure   - The wait failed with an error other than a
                            timeout; errno holds that error

The call never blocks for longer than the timeout, and each time it
wakes up it checks again whether sends are on. If the call fails,
msg->data still belongs to the caller.
 
With a timeout of 0 the call doesn't wait at all. It does exactly what
ccircq_try_send does and returns that result, so a full queue
gives ccol_container_full and not ccol_timed_out.
 
A timeout too large to form a deadline, such as UINT64_MAX, saturates
to the latest deadline the clock can hold, which in practice means
waiting with no end. It never wraps around into the past.
 
The timeout is measured on CLOCK_MONOTONIC. Changes to the system's
wall clock (made by an administrator, by NTP, or by resuming a virtual
machine) don't make it longer or shorter, and the call waits for the
duration that the caller gave.

ccircq_send(3), ccircq_try_send(3)