Extend field resetting in copyTo(SocketImpl) implementations niosocketimpl-branch
authoralanb
Wed, 13 Feb 2019 14:43:25 +0000
branchniosocketimpl-branch
changeset 57179 1774a7b73c72
parent 57178 738431fa8fb2
child 57185 e0e1493fa166
Extend field resetting in copyTo(SocketImpl) implementations
src/java.base/share/classes/java/net/AbstractPlainSocketImpl.java
src/java.base/share/classes/sun/nio/ch/NioSocketImpl.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");
         }
--- 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 {