Configure channel blocking as part of adding to the event-loop.
authorFredrik Tolf <fredrik@dolda2000.com>
Fri, 18 Feb 2022 03:56:57 +0000 (04:56 +0100)
committerFredrik Tolf <fredrik@dolda2000.com>
Fri, 18 Feb 2022 03:56:57 +0000 (04:56 +0100)
src/jagi/event/Driver.java
src/jagi/scgi/EventServer.java

index 6ee920f..8fe83a7 100644 (file)
@@ -184,6 +184,11 @@ public class Driver {
        void add(Watcher w, SelectableChannel ch) {
            if(watching.containsKey(w) || paused.containsKey(w) || timeheap.contains(w))
                throw(new IllegalStateException(w + ": already registered"));
+           try {
+               ch.configureBlocking(false);
+           } catch(IOException e) {
+               throw(new RuntimeException(ch + ": could not make non-blocking", e));
+           }
            int evs = w.events();
            double timeout = w.timeout();
            boolean hastime = timeout < Double.POSITIVE_INFINITY;
index 1a6bc2a..2de2e86 100644 (file)
@@ -21,11 +21,6 @@ public class EventServer implements Runnable {
                                                                    tgt -> new Thread(tgt, "Request handler thread"));
 
     public EventServer(ServerSocketChannel sk, Function handler) {
-       try {
-           sk.configureBlocking(false);
-       } catch(IOException e) {
-           throw(new RuntimeException(e));
-       }
        this.sk = sk;
        this.handler = handler;
     }
@@ -431,11 +426,8 @@ public class EventServer implements Runnable {
        public int events() {return(SelectionKey.OP_ACCEPT);}
 
        public void handle(int events) throws IOException {
-           if((events & SelectionKey.OP_ACCEPT) != 0) {
-               SocketChannel cl = sk.accept();
-               cl.configureBlocking(false);
-               Driver.current().add(new Client(cl));
-           }
+           if((events & SelectionKey.OP_ACCEPT) != 0)
+               Driver.current().add(new Client(sk.accept()));
        }
 
        public void close() {