8221252: (sc) SocketChannel and its socket adaptor need to handle connection reset

Reviewed-by: bpb
This commit is contained in:
Alan Bateman 2019-03-22 11:35:35 +00:00
parent cc590f5765
commit 3a4d5db248
13 changed files with 507 additions and 88 deletions

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -34,13 +34,28 @@ import java.io.IOException;
*/
class SocketDispatcher extends NativeDispatcher {
SocketDispatcher() { }
/**
* Reads up to len bytes from a socket with special handling for "connection
* reset".
*
* @throws sun.net.ConnectionResetException if connection reset is detected
* @throws IOException if another I/O error occurs
*/
int read(FileDescriptor fd, long address, int len) throws IOException {
return FileDispatcherImpl.read0(fd, address, len);
return read0(fd, address, len);
}
/**
* Scattering read from a socket into len buffers with special handling for
* "connection reset".
*
* @throws sun.net.ConnectionResetException if connection reset is detected
* @throws IOException if another I/O error occurs
*/
long readv(FileDescriptor fd, long address, int len) throws IOException {
return FileDispatcherImpl.readv0(fd, address, len);
return readv0(fd, address, len);
}
int write(FileDescriptor fd, long address, int len) throws IOException {
@ -58,4 +73,16 @@ class SocketDispatcher extends NativeDispatcher {
void preClose(FileDescriptor fd) throws IOException {
FileDispatcherImpl.preClose0(fd);
}
// -- Native methods --
private static native int read0(FileDescriptor fd, long address, int len)
throws IOException;
private static native long readv0(FileDescriptor fd, long address, int len)
throws IOException;
static {
IOUtil.load();
}
}

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2008, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2008, 2019, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -31,6 +31,8 @@ import java.net.*;
import java.util.concurrent.*;
import java.io.IOException;
import java.io.FileDescriptor;
import sun.net.ConnectionResetException;
import sun.net.NetHooks;
import sun.net.util.SocketExceptions;
import sun.security.action.GetPropertyAction;
@ -415,6 +417,8 @@ class UnixAsynchronousSocketChannelImpl
enableReading();
if (x instanceof ClosedChannelException)
x = new AsynchronousCloseException();
if (x instanceof ConnectionResetException)
x = new IOException(x.getMessage());
exc = x;
} finally {
// restart poll in case of concurrent write
@ -546,6 +550,8 @@ class UnixAsynchronousSocketChannelImpl
} catch (Throwable x) {
if (x instanceof ClosedChannelException)
x = new AsynchronousCloseException();
if (x instanceof ConnectionResetException)
x = new IOException(x.getMessage());
exc = x;
} finally {
if (!pending)