Use -1 from Watcher.events() to signal closure, rather than 0.
authorFredrik Tolf <fredrik@dolda2000.com>
Mon, 14 Feb 2022 16:34:47 +0000 (17:34 +0100)
committerFredrik Tolf <fredrik@dolda2000.com>
Mon, 14 Feb 2022 16:34:47 +0000 (17:34 +0100)
src/jagi/event/Driver.java

index c9ca638..84238d2 100644 (file)
@@ -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;
            }