Module tch.socket.evloop
Lua C module exposing event loops.
See epoll(7) for more information on event loops.
See also:
Functions
evloop() | Create a new event loop. |
Class evloop
evloop:add(sk[, read_cb[, write_cb]]) | Add a socket to this event loop with the given callback(s). |
evloop:close() | Close this event loop. |
evloop:fd() | Return the underlying file descriptor of this event loop. |
evloop:remove(sk) | Remove the given socket or raw file descriptor from this event loop. |
evloop:run() | Run this event loop. |
Functions
- evloop()
-
Create a new event loop.
Returns:
-
evloop
The newly created event loop.
Or
- nil
- string Error message.
See also:
Class evloop
- evloop:add(sk[, read_cb[, write_cb]])
-
Add a socket to this event loop with the given callback(s).
Based on which callbacks are provided the socket will be monitored for the corresponding event type. At least one callback must be provided. Adding an already added socket is currently not supported.
Parameters:
- sk sk or int The socket or raw file descriptor to add to the event loop.
- read_cb func Callback function that will be called when the socket has data ready to be read. The callback will be called with two arguments: the event loop object and the socket object or raw file descriptor. (optional)
- write_cb func Callback function that will be called when the socket is ready to send more data. The callback will be called with two arguments: the event loop object and the socket object or raw file descriptor. (optional)
Returns:
-
boolean
true
Or
- nil
- string Error message.
- evloop:close()
-
Close this event loop.
Calling other methods on a closed event loop will result in errors. It's not an error to close an event loop more than once. Closing the event loop from one of your event callbacks will cause
Evloop:run
to return.See also:
- evloop:fd()
-
Return the underlying file descriptor of this event loop.
Returns:
-
int
The file descriptor.
- evloop:remove(sk)
-
Remove the given socket or raw file descriptor from
this event loop.
Trying to remove a socket that is not in this event loop will currently result in an error. However, removing a closed socket from this event loop will always succeed.
Parameters:
- sk sk or int The socket or raw file descriptor to remove from the event loop.
Returns:
-
boolean
true
Or
- nil
- string Error message.
- evloop:run()
-
Run this event loop.
Once started it will wait for events on the sockets added to this event loop and invoke the appropriate callback functions. Running an empty event loop will return immediately with no error. To break out of the event loop one of the callback functions must call evloop:close.
Returns:
-
boolean
true
Or
- nil
- string Error message.
See also: