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

Alan Bateman Alan.Bateman at oracle.com
Thu Mar 21 12:33:33 UTC 2019


This is, I hope, the last patch in the series to prepare the code in 
sun.nio.ch for the NIO based SocketImpl. This last patch mostly concerns 
the behavior when reading after a connection reset has been detected. 
SocketChannel has not historically done any special handling for case 
case so reading after a connection reset behaves inconsistently (it 
returns whatever the operating system, e.g. Windows returns an error, 
Unix/macOS return -1/EOF). In classic networking, Socket::getInputStream 
specifies that subsequent reads throws IOException so that the 
read-after-reset behaves consistently on all platforms.

The proposal here is to update SocketChannel read to implement the 
behavior specified by Socket::getInputStream, the rational is that the 
socket adaptor (returned by SocketChannel::socket) needs to implement 
that behavior anyway. This change helps the NIO based SocketImpl effort 
as it allows the same underlying I/O methods can be used.

There are a fews cleanups in this patch but nothing of any significance: 
Net.pollConnect is changed to return a boolean rather than 0/1 and Net 
is also updated to new setSocketOption/getSocketOption methods to avoid 
needing to specify the "UNSPEC" family. If they are a distraction then I 
can move them to another patch, they are only included here to align 
jdk/jdk with the minor cleanups in the niosocketimpl-branch.

The webrev with the changes is here. The new test exercises 
SocketChannel.read and the socket adaptor read/available methods for 
cases where the connection is reset.

http://cr.openjdk.java.net/~alanb/8221252/webrev/

-Alan


More information about the nio-dev mailing list