From: Fredrik Tolf Date: Mon, 14 Feb 2022 16:34:47 +0000 (+0100) Subject: Use -1 from Watcher.events() to signal closure, rather than 0. X-Git-Url: http://dolda2000.com/gitweb/?p=jagi.git;a=commitdiff_plain;h=2c1781f3f6ef1f48af308b2a28ede6ae5c411d9a Use -1 from Watcher.events() to signal closure, rather than 0. --- 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; }