# HG changeset patch # User chegar # Date 1522352953 -3600 # Node ID 98075dcd4ffc7368444f22bc86183e6db6628b17 # Parent 5497ce4262763abc737669b148c0f1073a9629f1 http-client-branch: review comment - minor cleanups in SocketTube diff -r 5497ce426276 -r 98075dcd4ffc src/java.net.http/share/classes/jdk/internal/net/http/SocketTube.java --- a/src/java.net.http/share/classes/jdk/internal/net/http/SocketTube.java Thu Mar 29 20:22:55 2018 +0100 +++ b/src/java.net.http/share/classes/jdk/internal/net/http/SocketTube.java Thu Mar 29 20:49:13 2018 +0100 @@ -914,33 +914,32 @@ ByteBuffer buf = buffersSource.get(); assert buf.hasRemaining(); - int read = -1; + int read; int pos = buf.position(); List list = null; while (buf.hasRemaining()) { try { while ((read = channel.read(buf)) > 0) { - if (!buf.hasRemaining()) break; + if (!buf.hasRemaining()) + break; } } catch (IOException x) { if (buf.position() == pos && (list == null || list.isEmpty())) { - // if we have read no bytes, just throw... + // no bytes have been read, just throw... throw x; } else { - // we have some bytes. return them and fail - // next time. + // some bytes have been read, return them and fail next time errorRef.compareAndSet(null, x); - read = 0; // make sure we will exit the outer loop + read = 0; // ensures outer loop will exit } } // nothing read; if (buf.position() == pos) { - // An empty list signal the end of data, and should only be - // returned if read == -1. - // If we already read some data, then we must return what we have - // read, and -1 will be returned next time the caller attempts to - // read something. + // An empty list signals the end of data, and should only be + // returned if read == -1. If some data has already been read, + // then it must be returned. -1 will be returned next time + // the caller attempts to read something. if (list == null && read == -1) { // eof list = EOF; break; @@ -956,7 +955,10 @@ } list.add(buf); } - if (read <= 0 || list.size() == MAX_BUFFERS) break; + if (read <= 0 || list.size() == MAX_BUFFERS) { + break; + } + buf = buffersSource.get(); pos = buf.position(); assert buf.hasRemaining();