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;
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);
eof = true;
} else if(rv > 0) {
lastread = now;
- cur += rv;
+ if((cur += rv) >= max)
+ eof = true;
}
buf.flip();
while(buf.remaining() > 0)