# HG changeset patch # User alanb # Date 1550069005 0 # Node ID 1774a7b73c72061035bd9f01d4372eef909c1e54 # Parent 738431fa8fb2afba4e819d420f8e3f6f8769f715 Extend field resetting in copyTo(SocketImpl) implementations diff -r 738431fa8fb2 -r 1774a7b73c72 src/java.base/share/classes/java/net/AbstractPlainSocketImpl.java --- a/src/java.base/share/classes/java/net/AbstractPlainSocketImpl.java Wed Feb 13 08:29:35 2019 +0000 +++ b/src/java.base/share/classes/java/net/AbstractPlainSocketImpl.java Wed Feb 13 14:43:25 2019 +0000 @@ -753,12 +753,19 @@ assert fd.valid() && localport != 0 && address != null && port != 0; AbstractPlainSocketImpl psi = (AbstractPlainSocketImpl) si; + + // copy fields psi.stream = this.stream; psi.fd = this.fd; - psi.closePending = false; psi.localport = this.localport; psi.address = this.address; psi.port = this.port; + + // reset fields; do not reset timeout + psi.closePending = false; + psi.connectionReset = false; + psi.shut_rd = false; + psi.shut_wr = false; } else { throw new RuntimeException("not implemented"); } diff -r 738431fa8fb2 -r 1774a7b73c72 src/java.base/share/classes/sun/nio/ch/NioSocketImpl.java --- a/src/java.base/share/classes/sun/nio/ch/NioSocketImpl.java Wed Feb 13 08:29:35 2019 +0000 +++ b/src/java.base/share/classes/sun/nio/ch/NioSocketImpl.java Wed Feb 13 14:43:25 2019 +0000 @@ -434,18 +434,25 @@ && localport != 0 && address != null && port != 0; // copy fields + nsi.stream = this.stream; nsi.fd = this.fd; - nsi.stream = this.stream; - nsi.closer = FileDescriptorCloser.create(nsi); nsi.localport = this.localport; nsi.address = this.address; nsi.port = this.port; + + // reset fields; do not reset timeout + nsi.nonBlocking = false; + nsi.isInputClosed = false; + nsi.isOutputClosed = false; + nsi.isReuseAddress = false; nsi.state = ST_CONNECTED; - // disable closer to prevent GC'ing of this impl from - // closing the file descriptor + // GC'ing of this impl should not close the file descriptor this.closer.disable(); this.state = ST_CLOSED; + + // create new closer to execute when nsi is GC'ed + nsi.closer = FileDescriptorCloser.create(nsi); } } } else {