select_attach()
Attach a file descriptor to a dispatch handle
Synopsis:
#include <sys/iofunc.h> #include <sys/dispatch.h> int select_attach ( void *dpp, select_attr_t *attr, int fd, unsigned flags, int (*func)( select_context_t *ctp, int fd, unsigned flags, void *handle ), void *handle );
Arguments:
- dpp
- The dispatch handle, as returned by dispatch_create() , that you want to attach to a file descriptor.
- attr
- A pointer to a select_attr_t structure. This structure is defined as:
typedef struct _select_attr { unsigned flags; } select_attr_t;
Currently, no attribute flags are defined.
- fd
- The file descriptor that you want to attach to the dispatch handle.
- flags
- Flags that specify the events that you're interested in. For more information, see Flags, below.
- func
- The function that you want to call when the file descriptor unblocks. For more information, see Function, below.
- handle
- A pointer to arbitrary data that you want to pass to func.
Library:
libc
Use the -l c option to qcc to link against this library. This library is usually included automatically.
Description:
The function select_attach() attaches the file descriptor fd to the dispatch handle dpp and selects flags events. When fd unblocks, func is called with handle.
Flags
The available flags are defined in <sys/dispatch.h>. The following flags use ionotify() mechanisms (see ionotify() for further details):
- SELECT_FLAG_EXCEPT
- Out-of-band data is available. The definition of out-of-band data depends on the resource manager.
- SELECT_FLAG_READ
- There's input data available. The amount of data available defaults to 1. For a character device such as a serial port, this is a character. For a POSIX message queue, it's a message. Each resource manager selects an appropriate object.
- SELECT_FLAG_WRITE
- There's room in the output buffer for more data. The amount of room available needed to satisfy this condition depends on the resource manager. Some resource managers may default to an empty output buffer, while others may choose some percentage of the empty buffer.
These flags are specific to dispatch:
- SELECT_FLAG_REARM
- Rearm the fd after an event is dispatched.
- SELECT_FLAG_SRVEXCEPT
- Register a function that's called whenever a server, to which this client is connected, dies. (This flag uses the ChannelCreate() function's _NTO_CHF_COID_DISCONNECT flag. In this case, fd is ignored.)
Function
The argument func is the user-supplied function that's called when one of the registered events occurs on fd. This function should return 0 (zero); other values are reserved. The function is passed the following arguments:
- ctp
- Context pointer.
- fd
- The fd on which the event occurred.
- flags
- The type of event that occurred. The possible flags are:
- SELECT_FLAG_EXCEPT
- SELECT_FLAG_READ
- SELECT_FLAG_WRITE
For descriptions of the flags passed to func, see Flags, above.
- handle
- The handle passed to select_attach().
Returns:
Zero on success, or -1 if an error occurred (errno is set).
Errors:
- EINVAL
- Invalid argument.
- ENOMEM
- Insufficient memory was available.
Examples:
For an example with select_attach(), see dispatch_create() . For other examples using the dispatch interface, see message_attach() , resmgr_attach() , and thread_pool_create() .