X-Git-Url: http://dolda2000.com/gitweb/?a=blobdiff_plain;f=src%2Fjagi%2Fscgi%2FEventServer.java;h=f617cf54f5c7970aaf6b9263ef504b4f23da415f;hb=HEAD;hp=2de2e86fef0c6d98c893f9489b46967e601d5dad;hpb=1ee6412bc01b15aa8fad07a8bbce694ca099a8cb;p=jagi.git diff --git a/src/jagi/scgi/EventServer.java b/src/jagi/scgi/EventServer.java index 2de2e86..f617cf5 100644 --- a/src/jagi/scgi/EventServer.java +++ b/src/jagi/scgi/EventServer.java @@ -115,11 +115,14 @@ public class EventServer implements Runnable { public void handle(int events) throws IOException { if(!eof && (buf.remaining() == 0)) { - buf.rewind(); + buf.clear(); while(buf.remaining() > 0) { - if(in.read(buf) < 0) + if(in.read(buf) < 0) { + eof = true; break; + } } + buf.flip(); } double now = Driver.current().time(); if((events & SelectionKey.OP_WRITE) != 0) { @@ -168,7 +171,7 @@ public class EventServer implements Runnable { public void handle(int events) throws IOException { double now = Driver.current().time(); if((events & SelectionKey.OP_READ) != 0) { - buf.rewind(); + buf.clear(); if(buf.remaining() > max - cur) buf.limit(buf.position() + (int)Math.min(max - cur, Integer.MAX_VALUE)); int rv = sk.read(buf); @@ -176,7 +179,8 @@ public class EventServer implements Runnable { eof = true; } else if(rv > 0) { lastread = now; - cur += rv; + if((cur += rv) >= max) + eof = true; } buf.flip(); while(buf.remaining() > 0) @@ -334,6 +338,7 @@ public class EventServer implements Runnable { int headlen = 0; ByteBuffer head = null; Map env = null; + Request req = null; Client(SocketChannel sk) { this.sk = sk; @@ -401,8 +406,7 @@ public class EventServer implements Runnable { if((events & SelectionKey.OP_READ) != 0) { if((env == null) && !readhead()) return; - Request req = new Request(env, sk); - submit(() -> EventServer.this.handle(req, handler)); + req = new Request(env, sk); handoff = true; } if(Driver.current().time() > (lastread + timeout)) @@ -410,6 +414,8 @@ public class EventServer implements Runnable { } public void close() { + if(req != null) + submit(() -> EventServer.this.handle(req, handler)); if(!handoff) { try { sk.close();