Make sure to report EOF when reading from a socket channel

This commit is contained in:
Eric Scharff 2007-10-05 15:51:06 -06:00
parent 98269286e5
commit 19b6e11cbc
2 changed files with 3 additions and 0 deletions

View File

@ -271,6 +271,8 @@ Java_java_nio_channels_SocketChannel_natRead(JNIEnv *e,
} else { } else {
throwIOException(e); throwIOException(e);
} }
} else if (r == 0) {
return -1;
} }
return r; return r;
} }

View File

@ -44,6 +44,7 @@ public class SocketChannel extends SelectableChannel
} }
public int read(ByteBuffer b) throws IOException { public int read(ByteBuffer b) throws IOException {
if (! open) return -1;
if (b.remaining() == 0) return 0; if (b.remaining() == 0) return 0;
int r = natRead(socket, b.array(), b.arrayOffset() + b.position(), b.remaining()); int r = natRead(socket, b.array(), b.arrayOffset() + b.position(), b.remaining());
b.position(b.position() + r); b.position(b.position() + r);