File Descriptor Programming Interface
3-7
Sockets and Stream IO API
Wait on One or Multiple File Events
fdSelect
Syntax
int fdSelect( int maxfd, fd_set *readset, fd_set *writeset, fd_set *exceptset,
struct timeval *timeout );
Parameter(s)
maxfd
The highest index contained in any of the three supplied
descriptor sets
readset
Set of file descriptors to check for reading
writeset
Set of file descriptors to check for writing
exceptset
Set of file descriptors to check for exceptional conditions
(OOB data)
timeout
Pointer to timeval structure of time to wait (or NULL)
Return Value
Returns a positive count of ready descriptors (combined from all three possible
sets), 0 on timeout, or –1 on error. When an error occurs, the error type can
be obtained by calling fdError().
Description
This function allows the task to instruct the stack to wait for any one of multiple
events to occur and to wake up the process only when one of more of these
events occurs or when a specified amount of time has passed.
The definition of the timeval structure is:
struct timeval {
INT32 tv_sec;
INT32 tv_usec;
};
Passing in a NULL pointer for timeout specifies an infinite wait period. Passing
a valid pointer to a timeval structure with both tv_sec and tv_usec set to zero
specifies that the function should not block.
Close File Descriptor
fdClose
Syntax
int fdClose( int fd );
Parameter(s)
Return Value
0 on success or –1 on error. When an error occurs, the error type can be ob-
tained by calling fdError() (errno is also equated to this function).
Description
This function closes the indicated file descriptor.
Get the Last File Error
fdError
Syntax
int fdError();
Description
This function returns the last file error that occurred on the current task. In the
ERRNO.H header file, errno is equated to this function.