C Collections

cthreadcomm · Section 3

ccircq_timed_recv

ccircq_timed_recv - receive a message with a timeout

C Collections (libccollections, -lccollections)

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

Works like ccircq_recv(), but waits for a message for at most
timeout_us microseconds.

cq          Circular queue to receive from
target_buf  Buffer that gets the message
timeout_us  Longest time to wait, in microseconds, from the call. 0
            does not wait, which makes the call ccircq_try_recv.

ccol_success              - A message was received
ccol_invalid_args         - cq or target_buf is NULL
ccol_container_empty      - The timeout is 0 and the queue is empty
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. After a successful
call the data belongs to the caller, who must free target_buf->data.
 
With a timeout of 0 the call doesn't wait at all. It does exactly what
ccircq_try_recv does and returns that result, so an empty queue
gives ccol_container_empty 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_recv(3), ccircq_try_recv(3)