bps_add_fd()

Add a file descriptor to the currently active channel.

Synopsis:

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

Since:

BlackBerry 10.0.0

Arguments:

fd

The file descriptor to start monitoring.

io_events

The I/O conditions to monitor for.

io_handler

The I/O callback that is called whenever I/O conditions are met.

data

User supplied data that will be given to the I/O callback as the third argument.

Library:

libbps (For the qcc command, use the -l bps option to link against this library)

Description:

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 is 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. If the io_handler callback returns BPS_FAILURE, io_handler callback will no longer be called to handle the specified condtions.

Returns:

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

See also:

bps_remove_fd

Last modified: 2014-09-30



Got questions about leaving a comment? Get answers from our Disqus FAQ.

comments powered by Disqus