Module posix.poll
Synchronous I/O Multiplexing.
Examine file descriptors for events, such as readyness for I/O.
Functions
poll (fds[, timeout=-1]) | Wait for events on multiple file descriptors. |
rpoll (fd[, timeout=-1]) | Wait for some event on a file descriptor. |
Functions
- poll (fds[, timeout=-1])
-
Wait for events on multiple file descriptors.
Parameters:
- fds table list of file descriptors
- timeout int maximum timeout in milliseconds, or -1 to block indefinitely (default -1)
Returns:
-
int
0
if timed out, number of fd's ready if successfulOr
- nil
- string error message
- int errnum
See also:
- rpoll (fd[, timeout=-1])
-
Wait for some event on a file descriptor.
Based on a lua-l list post.
Parameters:
- fd int file descriptor
- timeout
int
maximum timeout in milliseconds, or
-1
to block indefinitely (default -1)
Returns:
-
int
0
if timed out, number of fd's ready if successfulOr
- nil
- error message
- int errnum
See also:
Usage:
fh = io.open "one" while true do r = rpoll (fh, 500) if r == 0 then print 'timeout' elseif r == 1 then print (fh:read ()) else print "finish!" break end end