VxWorks Reference Manual : Libraries

selectLib

NAME

selectLib - UNIX BSD 4.3 select library

ROUTINES

selectInit( ) - initialize the select facility
select( ) - pend on a set of file descriptors
selWakeup( ) - wake up a task pended in select( )
selWakeupAll( ) - wake up all tasks in a select( ) wake-up list
selNodeAdd( ) - add a wake-up node to a select( ) wake-up list
selNodeDelete( ) - find and delete a node from a select( ) wake-up list
selWakeupListInit( ) - initialize a select( ) wake-up list
selWakeupListLen( ) - get the number of nodes in a select( ) wake-up list
selWakeupType( ) - get the type of a select( ) wake-up node

DESCRIPTION

This library provides a BSD 4.3 compatible select facility to wait for activity on a set of file descriptors. selectLib provides a mechanism that gives a driver the ability to detect pended tasks that are awaiting activity on the driver's device. This allows a driver's interrupt service routine to wake up such tasks directly, eliminating the need for polling. The maximum number of file descriptors supported is 256.

Applications can use select( ) with pipes and serial devices, in addition to sockets. Also, select( ) examines write file descriptors in addition to read file descriptors; however, exception file descriptors remain unsupported.

Typically, application developers need concern themselves only with the select( ) call. However, driver developers should become familiar with the other routines that may be used with select( ), if they wish to support the select( ) mechanism.

INCLUDE FILES

selectLib.h

SEE ALSO

selectLib, VxWorks Programmer's Guide: I/O System


Libraries : Routines

selectInit( )

NAME

selectInit( ) - initialize the select facility

SYNOPSIS


void selectInit (void)

DESCRIPTION

This routine initializes the UNIX BSD 4.3 select facility. It should be called only once, and typically is called from the root task, usrRoot( ), in usrConfig.c. It installs a task delete hook that cleans up after a task if the task is deleted while pended in select( ).

RETURNS

N/A

SEE ALSO

selectLib


Libraries : Routines

select( )

NAME

select( ) - pend on a set of file descriptors

SYNOPSIS

int select
    (
    int              width,      /* number of bits to examine from 0 */
    fd_set *         pReadFds,   /* read fds */
    fd_set *         pWriteFds,  /* write fds */
    fd_set *         pExceptFds, /* exception fds (unsupported) */
    struct timeval * pTimeOut    /* max time to wait, NULL = forever */
    )

DESCRIPTION

This routine permits a task to pend until one of a set of file descriptors becomes ready. Three parameters -- pReadFds, pWriteFds, and pExceptFds -- point to file descriptor sets in which each bit corresponds to a particular file descriptor. Bits set in the read file descriptor set (pReadFds) will cause select( ) to pend until data is available on any of the corresponding file descriptors, while bits set in the write file descriptor set (pWriteFds) will cause select( ) to pend until any of the corresponding file descriptors become writable. (The pExceptFds parameter is currently unused, but is provided for UNIX call compatibility.)

The following macros are available for setting the appropriate bits in the file descriptor set structure:

    FD_SET(fd, &fdset)
    FD_CLR(fd, &fdset)
    FD_ZERO(&fdset)
If either pReadFds or pWriteFds is NULL, they are ignored. The width parameter defines how many bits will be examined in the file descriptor sets, and should be set to either the maximum file descriptor value in use plus one, or simply to FD_SETSIZE. When select( ) returns, it zeros out the file descriptor sets, and sets only the bits that correspond to file descriptors that are ready. The FD_ISSET macro may be used to determine which bits are set.

If pTimeOut is NULL, select( ) will block indefinitely. If pTimeOut is not NULL, but points to a timeval structure with an effective time of zero, the file descriptors in the file descriptor sets will be polled and the results returned immediately. If the effective time value is greater than zero, select( ) will return after the specified time has elapsed, even if none of the file descriptors are ready.

Applications can use select( ) with pipes and serial devices, in addition to sockets. Also, select( ) now examines write file descriptors in addition to read file descriptors; however, exception file descriptors remain unsupported.

Driver developers should consult the VxWorks Programmer's Guide: I/O System for details on writing drivers that will use select( ).

RETURNS

The number of file descriptors with activity, 0 if timed out, or ERROR if an error occurred when the driver's select( ) routine was invoked via ioctl( ).

SEE ALSO

selectLib, VxWorks Programmer's Guide: I/O System


Libraries : Routines

selWakeup( )

NAME

selWakeup( ) - wake up a task pended in select( )

SYNOPSIS

void selWakeup
    (
    SEL_WAKEUP_NODE * pWakeupNode /* node to wake up */
    )

DESCRIPTION

This routine wakes up a task pended in select( ). Once a driver's FIOSELECT function installs a wake-up node in a device's wake-up list (using selNodeAdd( )) and checks to make sure the device is ready, this routine ensures that the select( ) call does not pend.

RETURNS

N/A

SEE ALSO

selectLib


Libraries : Routines

selWakeupAll( )

NAME

selWakeupAll( ) - wake up all tasks in a select( ) wake-up list

SYNOPSIS

void selWakeupAll
    (
    SEL_WAKEUP_LIST * pWakeupList, /* list of tasks to wake up */
    SELECT_TYPE       type         /* readers (SELREAD) or writers (SELWRITE) */
    )

DESCRIPTION

This routine wakes up all tasks pended in select( ) that are waiting for a device; it is called by a driver when the device becomes ready. The type parameter specifies the task to be awakened, either reader tasks (SELREAD) or writer tasks (SELWRITE).

RETURNS

N/A

SEE ALSO

selectLib


Libraries : Routines

selNodeAdd( )

NAME

selNodeAdd( ) - add a wake-up node to a select( ) wake-up list

SYNOPSIS

STATUS selNodeAdd
    (
    SEL_WAKEUP_LIST * pWakeupList, /* list of tasks to wake up */
    SEL_WAKEUP_NODE * pWakeupNode  /* node to add to list */
    )

DESCRIPTION

This routine adds a wake-up node to a device's wake-up list. It is typically called from a driver's FIOSELECT function.

RETURNS

OK, or ERROR if memory is insufficient.

SEE ALSO

selectLib


Libraries : Routines

selNodeDelete( )

NAME

selNodeDelete( ) - find and delete a node from a select( ) wake-up list

SYNOPSIS

STATUS selNodeDelete
    (
    SEL_WAKEUP_LIST * pWakeupList, /* list of tasks to wake up */
    SEL_WAKEUP_NODE * pWakeupNode  /* node to delete from list */
    )

DESCRIPTION

This routine deletes a specified wake-up node from a specified wake-up list. Typically, it is called by a driver's FIOUNSELECT function.

RETURNS

OK, or ERROR if the node is not found in the wake-up list.

SEE ALSO

selectLib


Libraries : Routines

selWakeupListInit( )

NAME

selWakeupListInit( ) - initialize a select( ) wake-up list

SYNOPSIS

void selWakeupListInit
    (
    SEL_WAKEUP_LIST * pWakeupList /* wake-up list to initialize */
    )

DESCRIPTION

This routine should be called in a device's create routine to initialize the SEL_WAKEUP_LIST structure.

RETURNS

N/A

SEE ALSO

selectLib


Libraries : Routines

selWakeupListLen( )

NAME

selWakeupListLen( ) - get the number of nodes in a select( ) wake-up list

SYNOPSIS

int selWakeupListLen
    (
    SEL_WAKEUP_LIST * pWakeupList /* list of tasks to wake up */
    )

DESCRIPTION

This routine returns the number of nodes in a specified SEL_WAKEUP_LIST. It can be used by a driver to determine if any tasks are currently pended in select( ) on this device, and whether these tasks need to be activated with selWakeupAll( ).

RETURNS

The number of nodes currently in a select( ) wake-up list, or ERROR.

SEE ALSO

selectLib


Libraries : Routines

selWakeupType( )

NAME

selWakeupType( ) - get the type of a select( ) wake-up node

SYNOPSIS

SELECT_TYPE selWakeupType
    (
    SEL_WAKEUP_NODE * pWakeupNode /* node to get type of */
    )

DESCRIPTION

This routine returns the type of a specified SEL_WAKEUP_NODE. It is typically used in a device's FIOSELECT function to determine if the device is being selected for read or write operations.

RETURNS

SELREAD (read operation) or SELWRITE (write operation).

SEE ALSO

selectLib