Adds a file descriptor to the currently active channel.


#include <bps/bps.h>
BPS_API int bps_add_fd(int fd, int io_events, int(*io_handler)(int, int, void *), void *data)


The file descriptor to start monitoring.
The I/O conditions to monitor for.
The I/O callback that is called whenever I/O conditions are met.
User supplied data that will be given to the I/O callback as the third argument.




Call the function when a service wants to include a file descriptor in the active channel's set of file descriptors. At that time, the channel includes the supplied file descriptor into the set of file descriptors that it monitoring. When the I/O conditions, specified in io_events, are met then the channel calls the io_handler callback supplied.

An error occurs when you add a file descriptor that was already added to the channel.

You can perform a bitwise OR to bps_io_events_t enumerations and pass it as a second argument to specify the I/O conditions that the channel monitors.

For example, the code that follows shows when you want to monitor for input and supply no user data:

 bps_add_fd(fd, BPS_IO_INPUT, &io_handler, NULL);

The code that follows shows how to monitor for input and errors, with a channel specific data "service":

 bps_add_fd(service->fd, BPS_IO_INPUT | BPS_IO_EXCEPT, &io_handler, &service);

The io_handler callback is called whenever io_events I/O conditions are present for the file descriptor. The first argument will be the file descriptor, the second argument will be one or more bps_io_events_t enumerated values to indicate which conditions are present. The third argument is the user data.


BPS_SUCCESS if the fd (file descriptor) was successfully added to the channel, BPS_FAILURE with the errno value set otherwise.