Channel


 #include <cio/channel.h> 

Data Structures

struct  cio_channel_op
 Description of a multiplexed channel operation. More...
struct  cio_channel
 Opaque channel object. More...

Enumerations

enum  cio_channel_op_type { CIO_CHANNEL_READ, CIO_CHANNEL_WRITE }

Functions

struct cio_channelcio_channel_create (size_t item_size)
struct cio_channelcio_channel_ref (struct cio_channel *)
void cio_channel_unref (struct cio_channel *)
void cio_channel_close (struct cio_channel *)
int cio_channel_read (struct cio_channel *, void *item, size_t item_size)
int cio_channel_write (struct cio_channel *, const void *item, size_t item_size)
int cio_channel_select (const struct cio_channel_op *ops, int nops, int *selection)

Enumeration Type Documentation

Enumerator:
CIO_CHANNEL_READ 

Indicates a read operation.

CIO_CHANNEL_WRITE 

Indicates a write operation.


Function Documentation

void cio_channel_close ( struct cio_channel c  ) 

Mark the channel as closed. Writing is not possible immediately after this, and reading is not possible after all pending writes have been completed. This function may be called multiple times for a single channel.

struct cio_channel* cio_channel_create ( size_t  item_size  )  [read]

Create a new channel with a reference count of 1.

Parameters:
item_size size of items passed through this channel (may be 0)
Returns:
a channel or NULL on error
int cio_channel_read ( struct cio_channel c,
void *  item,
size_t  item_size 
)

Read an item from the channel.

Parameters:
c 
item buffer for the item or NULL if item_size is 0
item_size must match the channel's item size
Return values:
1 on success
0 if the channel is closed
-1 on error with errno set
struct cio_channel* cio_channel_ref ( struct cio_channel c  )  [read]

Increase the reference count.

Parameters:
c 
Returns:
c
int cio_channel_select ( const struct cio_channel_op ops,
int  nops,
int *  selection 
)

Perform one of multiple read and/or write operations.

Parameters:
ops vector of operations
nops number of operations
[out] selection storage for the index of the selected operation (set also on error; -1 on general error)
Return values:
1 if the selected operation performed
0 if the selected channel is closed
-1 on error with errno set
void cio_channel_unref ( struct cio_channel c  ) 

Decrease the reference count. The channel will be destroyed when there are no more references.

int cio_channel_write ( struct cio_channel c,
const void *  item,
size_t  item_size 
)

Write an item to the channel.

Parameters:
c 
item the item or NULL if item_size is 0
item_size must match the channel's item size
Return values:
1 on success
0 if the channel is closed
-1 on error with errno set