Cleanup niosocketimpl-branch
authormichaelm
Mon, 11 Feb 2019 15:17:31 +0000
branchniosocketimpl-branch
changeset 57176 726630bc6a4c
parent 57175 7eb6cdd1204a
child 57177 0b5ebb227a8d
Cleanup
src/java.base/share/classes/java/net/AbstractPlainSocketImpl.java
src/java.base/share/classes/java/net/DelegatingSocketImpl.java
src/java.base/share/classes/java/net/ServerSocket.java
src/java.base/share/classes/java/net/SocketImpl.java
src/java.base/share/classes/sun/net/PlatformSocketImpl.java
src/java.base/share/classes/sun/net/TrustedSocketImpl.java
src/java.base/share/classes/sun/nio/ch/NioSocketImpl.java
--- a/src/java.base/share/classes/java/net/AbstractPlainSocketImpl.java	Mon Feb 11 08:39:50 2019 +0000
+++ b/src/java.base/share/classes/java/net/AbstractPlainSocketImpl.java	Mon Feb 11 15:17:31 2019 +0000
@@ -39,8 +39,8 @@
 
 import sun.net.ConnectionResetException;
 import sun.net.NetHooks;
+import sun.net.PlatformSocketImpl;
 import sun.net.ResourceManager;
-import sun.net.TrustedSocketImpl;
 import sun.net.util.SocketExceptions;
 
 /**
@@ -50,7 +50,7 @@
  *
  * @author  Steven B. Byrne
  */
-abstract class AbstractPlainSocketImpl extends SocketImpl implements TrustedSocketImpl {
+abstract class AbstractPlainSocketImpl extends SocketImpl implements PlatformSocketImpl {
     /* instance variable for SO_TIMEOUT */
     int timeout;   // timeout in millisec
     // traffic class
@@ -734,7 +734,7 @@
 
     @Override
     @SuppressWarnings("unchecked")
-    public <S extends SocketImpl & TrustedSocketImpl> S newInstance(boolean server) {
+    public <S extends SocketImpl & PlatformSocketImpl> S newInstance(boolean server) {
         return (S) new PlainSocketImpl();
     }
 
--- a/src/java.base/share/classes/java/net/DelegatingSocketImpl.java	Mon Feb 11 08:39:50 2019 +0000
+++ b/src/java.base/share/classes/java/net/DelegatingSocketImpl.java	Mon Feb 11 15:17:31 2019 +0000
@@ -31,7 +31,7 @@
 import java.util.Objects;
 import java.util.Set;
 
-import sun.net.TrustedSocketImpl;
+import sun.net.PlatformSocketImpl;
 
 /**
  * A SocketImpl that delegates all methods to another SocketImpl.
@@ -41,7 +41,7 @@
     protected final SocketImpl delegate;
 
     DelegatingSocketImpl(SocketImpl delegate) {
-        assert delegate instanceof TrustedSocketImpl;
+        assert delegate instanceof PlatformSocketImpl;
         this.delegate = Objects.requireNonNull(delegate);
     }
 
--- a/src/java.base/share/classes/java/net/ServerSocket.java	Mon Feb 11 08:39:50 2019 +0000
+++ b/src/java.base/share/classes/java/net/ServerSocket.java	Mon Feb 11 15:17:31 2019 +0000
@@ -38,8 +38,7 @@
 import java.util.Set;
 import java.util.Collections;
 
-import sun.net.TrustedSocketImpl;
-import sun.nio.ch.NioSocketImpl;
+import sun.net.PlatformSocketImpl;
 
 /**
  * This class implements server sockets. A server socket waits for
@@ -553,8 +552,8 @@
             impl.accept(si);
             try {
                 // a custom impl has accepted the connection with a trusted SocketImpl
-                if (!(impl instanceof TrustedSocketImpl) && (si instanceof TrustedSocketImpl)) {
-                    ((TrustedSocketImpl) si).postCustomAccept();
+                if (!(impl instanceof PlatformSocketImpl) && (si instanceof PlatformSocketImpl)) {
+                    ((PlatformSocketImpl) si).postCustomAccept();
                 }
             } finally {
                 securityCheckAccept(si);  // closes si if permission check fails
@@ -569,19 +568,19 @@
         // Socket has a SOCKS or HTTP SocketImpl
         if (si instanceof DelegatingSocketImpl) {
             si = ((DelegatingSocketImpl) si).delegate();
-            assert si instanceof TrustedSocketImpl;
+            assert si instanceof PlatformSocketImpl;
         }
 
         // ServerSocket or Socket is using a trusted SocketImpl
-        if (impl instanceof TrustedSocketImpl || si instanceof TrustedSocketImpl) {
+        if (impl instanceof PlatformSocketImpl || si instanceof PlatformSocketImpl) {
             // accept connection with new SocketImpl
-            var nsi = (impl instanceof TrustedSocketImpl)
-                    ? ((TrustedSocketImpl) impl).newInstance(false)
-                    : ((TrustedSocketImpl) si).newInstance(false);
+            var nsi = (impl instanceof PlatformSocketImpl)
+                    ? ((PlatformSocketImpl) impl).newInstance(false)
+                    : ((PlatformSocketImpl) si).newInstance(false);
             impl.accept(nsi);
             try {
                 // a custom impl has accepted the connection with a trusted SocketImpl
-                if (!(impl instanceof TrustedSocketImpl)) {
+                if (!(impl instanceof PlatformSocketImpl)) {
                     nsi.postCustomAccept();
                 }
             } finally {
--- a/src/java.base/share/classes/java/net/SocketImpl.java	Mon Feb 11 08:39:50 2019 +0000
+++ b/src/java.base/share/classes/java/net/SocketImpl.java	Mon Feb 11 15:17:31 2019 +0000
@@ -52,13 +52,9 @@
     private static final boolean USE_PLAINSOCKETIMPL = usePlainSocketImpl();
 
     private static boolean usePlainSocketImpl() {
-        String s = GetPropertyAction.privilegedGetProperty("jdk.net.usePlainSocketImpl");
-        if (s != null && !"false".equalsIgnoreCase(s))
-            return true;
-
-        PrivilegedAction<String> pa = () -> NetProperties.get("jdk.net.socketimpl.default");
-        s = AccessController.doPrivileged(pa);
-        return (s != null) && "classic".equalsIgnoreCase(s);
+        PrivilegedAction<Boolean> pa = () -> NetProperties.getBoolean("jdk.net.usePlainSocketImpl");
+        Boolean val = AccessController.doPrivileged(pa);
+        return val == null ? false : val;
     }
 
     /**
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/java.base/share/classes/sun/net/PlatformSocketImpl.java	Mon Feb 11 15:17:31 2019 +0000
@@ -0,0 +1,55 @@
+/*
+ * Copyright (c) 2018, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package sun.net;
+
+import java.io.IOException;
+import java.net.SocketImpl;
+
+/**
+ * Implemented by the platform's SocketImpl implementations.
+ */
+
+public interface PlatformSocketImpl {
+
+    /**
+     * Creates a new instance of this SocketImpl.
+     */
+    <S extends SocketImpl & PlatformSocketImpl> S newInstance(boolean server);
+
+    /**
+     * Invoked by ServerSocket to fix up the SocketImpl state after a connection
+     * is accepted by a custom SocketImpl
+     */
+    void postCustomAccept() throws IOException;
+
+    /**
+     * Copy the state from this connected SocketImpl to a target SocketImpl. If
+     * the target SocketImpl is not a newly created SocketImpl then it is first
+     * closed to release any resources. The target SocketImpl becomes the owner
+     * of the file descriptor, this SocketImpl is marked as closed and should
+     * be discarded.
+     */
+    void copyTo(SocketImpl si);
+}
--- a/src/java.base/share/classes/sun/net/TrustedSocketImpl.java	Mon Feb 11 08:39:50 2019 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,55 +0,0 @@
-/*
- * Copyright (c) 2018, 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
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.  Oracle designates this
- * particular file as subject to the "Classpath" exception as provided
- * by Oracle in the LICENSE file that accompanied this code.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-package sun.net;
-
-import java.io.IOException;
-import java.net.SocketImpl;
-
-/**
- * Implemented by the platform's SocketImpl implementations.
- */
-
-public interface TrustedSocketImpl {
-
-    /**
-     * Creates a new instance of this SocketImpl.
-     */
-    <S extends SocketImpl & TrustedSocketImpl> S newInstance(boolean server);
-
-    /**
-     * Invoked by ServerSocket to fix up the SocketImpl state after a connection
-     * is accepted by a custom SocketImpl
-     */
-    void postCustomAccept() throws IOException;
-
-    /**
-     * Copy the state from this connected SocketImpl to a target SocketImpl. If
-     * the target SocketImpl is not a newly created SocketImpl then it is first
-     * closed to release any resources. The target SocketImpl becomes the owner
-     * of the file descriptor, this SocketImpl is marked as closed and should
-     * be discarded.
-     */
-    void copyTo(SocketImpl si);
-}
--- a/src/java.base/share/classes/sun/nio/ch/NioSocketImpl.java	Mon Feb 11 08:39:50 2019 +0000
+++ b/src/java.base/share/classes/sun/nio/ch/NioSocketImpl.java	Mon Feb 11 15:17:31 2019 +0000
@@ -57,8 +57,8 @@
 import jdk.internal.access.SharedSecrets;
 import jdk.internal.ref.CleanerFactory;
 import sun.net.NetHooks;
+import sun.net.PlatformSocketImpl;
 import sun.net.ResourceManager;
-import sun.net.TrustedSocketImpl;
 import sun.net.ext.ExtendedSocketOptions;
 import sun.net.util.SocketExceptions;
 
@@ -81,7 +81,7 @@
  * an application continues to call read or available after a reset.
  */
 
-public final class NioSocketImpl extends SocketImpl implements TrustedSocketImpl {
+public final class NioSocketImpl extends SocketImpl implements PlatformSocketImpl {
     private static final NativeDispatcher nd = new SocketDispatcher();
 
     // The maximum number of bytes to read/write per syscall to avoid needing
@@ -398,7 +398,7 @@
      */
     @Override
     @SuppressWarnings("unchecked")
-    public <S extends SocketImpl & TrustedSocketImpl> S newInstance(boolean server) {
+    public <S extends SocketImpl & PlatformSocketImpl> S newInstance(boolean server) {
         return (S) new NioSocketImpl(server);
     }
 
@@ -1163,7 +1163,7 @@
                 throw new InternalError(e);
             }
         }
-        
+
         private final FileDescriptor fd;
         private final boolean stream;
         private volatile boolean closed;
@@ -1179,7 +1179,7 @@
             CleanerFactory.cleaner().register(impl, closer);
             return closer;
         }
-        
+
         @Override
         public void run() {
             if (CLOSED.compareAndSet(this, false, true)) {
@@ -1189,7 +1189,7 @@
                     throw new RuntimeException(ioe);
                 } finally {
                     if (!stream) {
-                        // decrement 
+                        // decrement
                         ResourceManager.afterUdpClose();
                     }
                 }