src/java.base/share/classes/sun/nio/ch/Net.java
branchrsocket-branch
changeset 57115 512e7cc6ccce
parent 53445 c96f9aa1f3d8
equal deleted inserted replaced
53485:b743968ad646 57115:512e7cc6ccce
    77     private static volatile boolean isReusePortAvailable;
    77     private static volatile boolean isReusePortAvailable;
    78 
    78 
    79     /**
    79     /**
    80      * Tells whether dual-IPv4/IPv6 sockets should be used.
    80      * Tells whether dual-IPv4/IPv6 sockets should be used.
    81      */
    81      */
    82     static boolean isIPv6Available() {
    82     public static boolean isIPv6Available() {
    83         if (!checkedIPv6) {
    83         if (!checkedIPv6) {
    84             isIPv6Available = isIPv6Available0();
    84             isIPv6Available = isIPv6Available0();
    85             checkedIPv6 = true;
    85             checkedIPv6 = true;
    86         }
    86         }
    87         return isIPv6Available;
    87         return isIPv6Available;
   148         if (!(sa instanceof InetSocketAddress))
   148         if (!(sa instanceof InetSocketAddress))
   149             throw new UnsupportedAddressTypeException();
   149             throw new UnsupportedAddressTypeException();
   150         return (InetSocketAddress)sa;
   150         return (InetSocketAddress)sa;
   151     }
   151     }
   152 
   152 
   153     static void translateToSocketException(Exception x)
   153     public static void translateToSocketException(Exception x)
   154         throws SocketException
   154         throws SocketException
   155     {
   155     {
   156         if (x instanceof SocketException)
   156         if (x instanceof SocketException)
   157             throw (SocketException)x;
   157             throw (SocketException)x;
   158         Exception nx = x;
   158         Exception nx = x;
   178             throw (RuntimeException)nx;
   178             throw (RuntimeException)nx;
   179         else
   179         else
   180             throw new Error("Untranslated exception", nx);
   180             throw new Error("Untranslated exception", nx);
   181     }
   181     }
   182 
   182 
   183     static void translateException(Exception x,
   183     public static void translateException(Exception x,
   184                                    boolean unknownHostForUnresolved)
   184                                    boolean unknownHostForUnresolved)
   185         throws IOException
   185         throws IOException
   186     {
   186     {
   187         if (x instanceof IOException)
   187         if (x instanceof IOException)
   188             throw (IOException)x;
   188             throw (IOException)x;
   194              throw new UnknownHostException();
   194              throw new UnknownHostException();
   195         }
   195         }
   196         translateToSocketException(x);
   196         translateToSocketException(x);
   197     }
   197     }
   198 
   198 
   199     static void translateException(Exception x)
   199     public static void translateException(Exception x)
   200         throws IOException
   200         throws IOException
   201     {
   201     {
   202         translateException(x, false);
   202         translateException(x, false);
   203     }
   203     }
   204 
   204 
   205     /**
   205     /**
   206      * Returns the local address after performing a SecurityManager#checkConnect.
   206      * Returns the local address after performing a SecurityManager#checkConnect.
   207      */
   207      */
   208     static InetSocketAddress getRevealedLocalAddress(InetSocketAddress addr) {
   208     public static InetSocketAddress getRevealedLocalAddress(InetSocketAddress addr) {
   209         SecurityManager sm = System.getSecurityManager();
   209         SecurityManager sm = System.getSecurityManager();
   210         if (addr == null || sm == null)
   210         if (addr == null || sm == null)
   211             return addr;
   211             return addr;
   212 
   212 
   213         try{
   213         try{
   218             addr = getLoopbackAddress(addr.getPort());
   218             addr = getLoopbackAddress(addr.getPort());
   219         }
   219         }
   220         return addr;
   220         return addr;
   221     }
   221     }
   222 
   222 
   223     static String getRevealedLocalAddressAsString(InetSocketAddress addr) {
   223     public static String getRevealedLocalAddressAsString(InetSocketAddress addr) {
   224         return System.getSecurityManager() == null ? addr.toString() :
   224         return System.getSecurityManager() == null ? addr.toString() :
   225                 getLoopbackAddress(addr.getPort()).toString();
   225                 getLoopbackAddress(addr.getPort()).toString();
   226     }
   226     }
   227 
   227 
   228     private static InetSocketAddress getLoopbackAddress(int port) {
   228     private static InetSocketAddress getLoopbackAddress(int port) {