aboutsummaryrefslogtreecommitdiffstats
path: root/src/io
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2024-10-02 16:57:25 +0200
committerbptato <nincsnevem662@gmail.com>2024-10-02 16:58:59 +0200
commitbca95ddbbe2e95c3e8a0a995c73fafe1e3015bd3 (patch)
treee1de4899e6708e60bc71cf47526395560207309f /src/io
parent491421e2e3e25358e2401b4c26c7d8dffdc5d507 (diff)
downloadchawan-bca95ddbbe2e95c3e8a0a995c73fafe1e3015bd3.tar.gz
poll: reset events on error
poll will return an error if interrupted, which may leave the events in their previous state. Make sure revents is set to 0 first.
Diffstat (limited to 'src/io')
-rw-r--r--src/io/poll.nim6
1 files changed, 5 insertions, 1 deletions
diff --git a/src/io/poll.nim b/src/io/poll.nim
index fe7aee56..5e115a11 100644
--- a/src/io/poll.nim
+++ b/src/io/poll.nim
@@ -42,6 +42,10 @@ proc poll*(ctx: var PollData; timeout: cint) =
ctx.trim()
let fds = addr ctx.fds[0]
let nfds = cint(ctx.fds.len)
+ var res: cint
{.emit: """
- poll(`fds`, `nfds`, `timeout`);
+ `res` = (int)poll(`fds`, `nfds`, `timeout`);
""".}
+ if res < 0: # error
+ for event in ctx.fds.mitems:
+ event.revents = 0