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, 1 if fd is ready
Or
- nil
- string error message
- int errnum
See also:
- rpoll (fd[, timeout=-1])
-
Wait for some event on a file descriptor.
Based on http://lua-users.org/lists/lua-l/2007-11/msg00346.html.
Parameters:
- fd int file descriptor
- timeout int maximum timeout in milliseconds, or -1 to block indefinitely (default -1)
Returns:
-
int
0 if timed out, 1 if fd is ready
Or
- 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