[Overview][Constants][Types][Procedures and functions] |
Wait for events on file descriptors
Source position: line 0
function FPSelect( |
N: cInt; |
readfds: pFDSet; |
writefds: pFDSet; |
exceptfds: pFDSet; |
TimeOut: ptimeval |
):cInt; |
N: cInt; |
readfds: pFDSet; |
writefds: pFDSet; |
exceptfds: pFDSet; |
TimeOut: cInt |
):cInt; |
var T: Text; |
TimeOut: ptimeval |
):cInt; |
var T: Text; |
TimeOut: time_t |
):cInt; |
FpSelectchecks one of the file descriptors in the FDSetsto see if its status changed.
readfds, writefdsand exceptfdsare pointers to arrays of 256 bits. If you want a file descriptor to be checked, you set the corresponding element in the array to 1. The other elements in the array must be set to zero. Three arrays are passed : The entries in readfdsare checked to see if characters become available for reading. The entries in writefdsare checked to see if it is OK to write to them, while entries in exceptfdsare cheked to see if an exception occorred on them.
You can use the functions fpFD_ZERO, fpFD_Clr, fpFD_Setor fpFD_IsSetto manipulate the individual elements of a set.
The pointers can be Nil.
Nis the largest index of a nonzero entry plus 1. (= the largest file-descriptor + 1).
TimeOutcan be used to set a time limit. If TimeOutcan be two types :
When the TimeOut is reached, or one of the file descriptors has changed, the Selectcall returns. On return, it will have modified the entries in the array which have actually changed, and it returns the number of entries that have been changed. If the timout was reached, and no decsriptor changed, zero is returned; The arrays of indexes are undefined after that. On error, -1 is returned.
The variant with the text file will execute the FpSelectcall on the file descriptor associated with the text file T
On error, the function returns -1. Extended error information can be retrieved using fpGetErrno.
|
Clear all file descriptors in set |
|
|
Clears a filedescriptor in a set |
|
|
Set a filedescriptor in a set |
|
|
Check whether a filedescriptor is set |
Program Example33; { Program to demonstrate the Select function. } Uses BaseUnix; Var FDS : Tfdset; begin fpfd_zero(FDS); fpfd_set(0,FDS); Writeln ('Press the <ENTER> to continue the program.'); { Wait until File descriptor 0 (=Input) changes } fpSelect (1,@FDS,nil,nil,nil); { Get rid of <ENTER> in buffer } readln; Writeln ('Press <ENTER> key in less than 2 seconds...'); Fpfd_zero(FDS); FpFd_set (0,FDS); if fpSelect (1,@FDS,nil,nil,2000)>0 then Writeln ('Thank you !') { FD_ISSET(0,FDS) would be true here. } else Writeln ('Too late !'); end.