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;
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;
}
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() {