Fixed some event-server channel-transfer bugs.
authorFredrik Tolf <fredrik@dolda2000.com>
Sat, 19 Feb 2022 00:45:28 +0000 (01:45 +0100)
committerFredrik Tolf <fredrik@dolda2000.com>
Sat, 19 Feb 2022 00:45:28 +0000 (01:45 +0100)
src/jagi/scgi/EventServer.java

index 202b8dd..8218973 100644 (file)
@@ -115,7 +115,7 @@ 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)
                        break;
@@ -168,7 +168,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 +176,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)