From 2c1781f3f6ef1f48af308b2a28ede6ae5c411d9a Mon Sep 17 00:00:00 2001 From: Fredrik Tolf Date: Mon, 14 Feb 2022 17:34:47 +0100 Subject: [PATCH] Use -1 from Watcher.events() to signal closure, rather than 0. --- src/jagi/event/Driver.java | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/jagi/event/Driver.java b/src/jagi/event/Driver.java index c9ca638..84238d2 100644 --- a/src/jagi/event/Driver.java +++ b/src/jagi/event/Driver.java @@ -138,7 +138,7 @@ public class Driver { int evs = w.events(); double timeout = w.timeout(); boolean hastime = timeout < Double.POSITIVE_INFINITY; - if((evs == 0) && !hastime) { + if(evs < 0) { remove(w); return; } @@ -154,10 +154,11 @@ public class Driver { int evs = w.events(); double timeout = w.timeout(); boolean hastime = timeout < Double.POSITIVE_INFINITY; - if((evs == 0) && !hastime) { - w.close(); + if(evs < 0) { + submit(w::close); return; } + w.added(Driver.this); try { watching.put(w, ch.register(poll, evs, w)); } catch(ClosedChannelException e) { @@ -178,7 +179,7 @@ public class Driver { throw(new RuntimeException(w + ": inconsistent internal state")); if(wc == null) throw(new IllegalStateException(w + ": not registered")); - w.close(); + submit(w::close); poll.wakeup(); } @@ -189,7 +190,7 @@ public class Driver { int evs = w.events(); double timeout = w.timeout(); boolean hastime = timeout < Double.POSITIVE_INFINITY; - if((evs == 0) && !hastime) { + if(evs < 0) { remove(w); return; } -- 2.11.0