cthreadcomm · Section 3
cchan_recv
NAME
cchan_recv - receive a message from the cchan (it blocks)
LIBRARY
C Collections (libccollections, -lccollections)
SYNOPSIS
#include <ccollections/cthreadcomm.h> ccol_retval cchan_recv(cchan *ch, cmessage *target_buf);
DESCRIPTION
Receives a message from the channel, waiting as long as it takes for one to arrive. The queue is chosen from the thread that calls it: The owner thread receives from the cchan_workers_to_owner queue and any other thread receives from the cchan_owner_to_workers queue. The message's data is handed over without a copy, so its ownership moves to the caller.
PARAMETERS
ch Channel to receive from
target_buf Buffer that gets the message together with the ownership
of the data.
RETURN VALUE
ccol_success - A message was received. The caller must free
target_buf->data.
ccol_invalid_args - ch or target_buf is NULL
NOTES
The call blocks until a message arrives in the chosen queue. The direction is decided from the ID of the calling thread, which is compared with the ID of the owner that the channel took at creation. target_buf->data belongs to the caller after a successful call, and the caller must free it.