- evh = app:add(fd, callback [, events])
- function callback(evh, fd, revents) ...
SYNOPSIS
DESCRIPTION
Adds an event handler for generic file descriptor events. The argument fd specifies a generic file descriptor, e.g. as returned by rawio:fd(). Whenever an event happens on this file descriptor, the callback function is called. Reported events are selected with the events parameter, which is a logical or of the following values:
POLLIN | Data can be read from the file descriptor. |
POLLOUT | Data can be written to the file descriptor. |
The default value for events is POLLIN.
This function is mostly used for receiving data from a serial port or network socket.
When the callback is called, the parameter revents contains a logical or of all events that are pending and have been asked for when calling app:add().
After adding, the event handler is enabled and performs as described. It can be disabled and enabled at runtime by calling its evh:disable() and evh:enable() methods.
RETURN VALUE
NOTES
Callbacks are called from within event:poll().
The file descriptor should not be in blocking mode when handled by the event system. The blocking mode can be disabled using rawio:blocking().
If you application seems to hang mysteriously, check if you have event handlers running on file descriptors in blocking mode.