cthreadcomm · Section 3
cchan_timed_recv
NAME
cchan_timed_recv - receive a message with a timeout
LIBRARY
C Collections (libccollections, -lccollections)
SYNOPSIS
#include <ccollections/cthreadcomm.h>
ccol_retval cchan_timed_recv(cchan *ch,
cmessage *target_buf,
uint64_t timeout_us);
DESCRIPTION
Works like cchan_recv(), but waits for a message for at most timeout_us microseconds. The queue is the one that the channel picks for the calling thread.
PARAMETERS
ch Channel 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 cchan_try_recv.
RETURN VALUE
ccol_success - A message was received
ccol_invalid_args - ch or target_buf is NULL
ccol_container_empty - The timeout is 0 and the chosen 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
NOTES
The call never blocks for longer than the timeout. The direction is decided from the ID of the calling thread. With a timeout of 0 the call doesn't wait at all. It does exactly what cchan_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.