mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-27 14:54:52 +02:00
8191025: (ch) Scattering reads to a subsequence of buffers ignores length
Use length parameter instead of the buffer array length Reviewed-by: rriggs, alanb
This commit is contained in:
parent
ccdb0ef8e2
commit
1ca74d0d2e
2 changed files with 25 additions and 3 deletions
|
@ -297,7 +297,7 @@ public class IOUtil {
|
||||||
NativeDispatcher nd)
|
NativeDispatcher nd)
|
||||||
throws IOException
|
throws IOException
|
||||||
{
|
{
|
||||||
return read(fd, bufs, offset, bufs.length, false, -1, nd);
|
return read(fd, bufs, offset, length, false, -1, nd);
|
||||||
}
|
}
|
||||||
|
|
||||||
static long read(FileDescriptor fd, ByteBuffer[] bufs, int offset, int length,
|
static long read(FileDescriptor fd, ByteBuffer[] bufs, int offset, int length,
|
||||||
|
|
|
@ -22,6 +22,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* @test
|
/* @test
|
||||||
|
* @bug 8191025
|
||||||
* @summary Test socketchannel vector IO (use -Dseed=X to set PRNG seed)
|
* @summary Test socketchannel vector IO (use -Dseed=X to set PRNG seed)
|
||||||
* @library .. /test/lib
|
* @library .. /test/lib
|
||||||
* @build jdk.test.lib.RandomFactory
|
* @build jdk.test.lib.RandomFactory
|
||||||
|
@ -42,11 +43,16 @@ public class VectorIO {
|
||||||
|
|
||||||
static int testSize;
|
static int testSize;
|
||||||
|
|
||||||
|
// whether to use the write/read variant with a length parameter
|
||||||
|
static boolean setLength;
|
||||||
|
|
||||||
public static void main(String[] args) throws Exception {
|
public static void main(String[] args) throws Exception {
|
||||||
testSize = 1;
|
testSize = 1;
|
||||||
|
setLength = false;
|
||||||
runTest();
|
runTest();
|
||||||
for(int i=15; i<18; i++) {
|
for(int i=15; i<18; i++) {
|
||||||
testSize = i;
|
testSize = i;
|
||||||
|
setLength = !setLength;
|
||||||
runTest();
|
runTest();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -75,6 +81,9 @@ public class VectorIO {
|
||||||
total += bufs[i].remaining();
|
total += bufs[i].remaining();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ByteBuffer[] bufsPlus1 = new ByteBuffer[bufs.length + 1];
|
||||||
|
System.arraycopy(bufs, 0, bufsPlus1, 0, bufs.length);
|
||||||
|
|
||||||
// Get a connection to the server
|
// Get a connection to the server
|
||||||
InetAddress lh = InetAddress.getLocalHost();
|
InetAddress lh = InetAddress.getLocalHost();
|
||||||
InetSocketAddress isa = new InetSocketAddress(lh, port);
|
InetSocketAddress isa = new InetSocketAddress(lh, port);
|
||||||
|
@ -85,7 +94,12 @@ public class VectorIO {
|
||||||
// Write the data out
|
// Write the data out
|
||||||
long rem = total;
|
long rem = total;
|
||||||
while (rem > 0L) {
|
while (rem > 0L) {
|
||||||
long bytesWritten = sc.write(bufs);
|
long bytesWritten;
|
||||||
|
if (setLength) {
|
||||||
|
bytesWritten = sc.write(bufsPlus1, 0, bufs.length);
|
||||||
|
} else {
|
||||||
|
bytesWritten = sc.write(bufs);
|
||||||
|
}
|
||||||
if (bytesWritten == 0) {
|
if (bytesWritten == 0) {
|
||||||
if (sc.isBlocking()) {
|
if (sc.isBlocking()) {
|
||||||
throw new RuntimeException("write did not block");
|
throw new RuntimeException("write did not block");
|
||||||
|
@ -134,6 +148,9 @@ public class VectorIO {
|
||||||
total += bufs[i].capacity();
|
total += bufs[i].capacity();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ByteBuffer[] bufsPlus1 = new ByteBuffer[bufs.length + 1];
|
||||||
|
System.arraycopy(bufs, 0, bufsPlus1, 0, bufs.length);
|
||||||
|
|
||||||
// Get a connection from client
|
// Get a connection from client
|
||||||
SocketChannel sc = null;
|
SocketChannel sc = null;
|
||||||
|
|
||||||
|
@ -155,7 +172,12 @@ public class VectorIO {
|
||||||
// Read data into multiple buffers
|
// Read data into multiple buffers
|
||||||
long avail = total;
|
long avail = total;
|
||||||
while (avail > 0) {
|
while (avail > 0) {
|
||||||
long bytesRead = sc.read(bufs);
|
long bytesRead;
|
||||||
|
if (setLength) {
|
||||||
|
bytesRead = sc.read(bufsPlus1, 0, bufs.length);
|
||||||
|
} else {
|
||||||
|
bytesRead = sc.read(bufs);
|
||||||
|
}
|
||||||
if (bytesRead < 0)
|
if (bytesRead < 0)
|
||||||
break;
|
break;
|
||||||
if (bytesRead == 0) {
|
if (bytesRead == 0) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue