]> git.lizzy.rs Git - hydra-dragonfire.git/blob - doc/poll.md
Merge pull request #4 from Minetest-j45/master
[hydra-dragonfire.git] / doc / poll.md
1 # Polling API
2 Source code: [poll.go](../poll.go)
3
4 `poll` waits for and returns the next event from one or more clients, or `nil` if none of the clients passed to it are active (`connected` state).
5 Optionally, a timeout can be passed to poll; if no other event occurs until the timeout elapses, a timeout event is returned.
6
7 ## Events
8
9 An event is a table that contains a string `type`. Depending on the type, it may have different other fields.
10
11 - `type = "interrupt"`: Fired globally when the program was interrupted using a signal.
12
13 - `type = "timeout"`: Fired when the timeout elapses.
14
15 - `type = "pkt"`: Fired when a packet was received. See [pkts.md](pkts.md)
16
17 - `type = "disconnect"`: Fired when a client connection closed. Has a `client` field. 
18
19 - `type = "error"`: Fired when an error occurs during deserialization of a packet. Has a `client` field. Stores the error message in an `error` field.