< prev index next >

src/java.base/share/classes/sun/nio/ch/Net.java

Print this page




  33 import java.net.InetSocketAddress;
  34 import java.net.NetworkInterface;
  35 import java.net.ProtocolFamily;
  36 import java.net.SocketAddress;
  37 import java.net.SocketException;
  38 import java.net.SocketOption;
  39 import java.net.StandardProtocolFamily;
  40 import java.net.StandardSocketOptions;
  41 import java.net.UnknownHostException;
  42 import java.nio.channels.AlreadyBoundException;
  43 import java.nio.channels.ClosedChannelException;
  44 import java.nio.channels.NotYetBoundException;
  45 import java.nio.channels.NotYetConnectedException;
  46 import java.nio.channels.UnresolvedAddressException;
  47 import java.nio.channels.UnsupportedAddressTypeException;
  48 import java.security.AccessController;
  49 import java.security.PrivilegedAction;
  50 import java.util.Enumeration;
  51 
  52 import sun.net.ext.ExtendedSocketOptions;
  53 import sun.net.util.IPAddressUtil;
  54 import sun.security.action.GetPropertyAction;
  55 
  56 public class Net {
  57 
  58     private Net() { }
  59 
  60     // unspecified protocol family
  61     static final ProtocolFamily UNSPEC = new ProtocolFamily() {
  62         public String name() {
  63             return "UNSPEC";
  64         }
  65     };
  66 
  67     // set to true if exclusive binding is on for Windows
  68     private static final boolean exclusiveBind;
  69 
  70     // set to true if the fast tcp loopback should be enabled on Windows
  71     private static final boolean fastLoopback;
  72 
  73     // -- Miscellaneous utilities --


 446 
 447     static FileDescriptor serverSocket(boolean stream) {
 448         return IOUtil.newFD(socket0(isIPv6Available(), stream, true, fastLoopback));
 449     }
 450 
 451     // Due to oddities SO_REUSEADDR on windows reuse is ignored
 452     private static native int socket0(boolean preferIPv6, boolean stream, boolean reuse,
 453                                       boolean fastLoopback);
 454 
 455     public static void bind(FileDescriptor fd, InetAddress addr, int port)
 456         throws IOException
 457     {
 458         bind(UNSPEC, fd, addr, port);
 459     }
 460 
 461     static void bind(ProtocolFamily family, FileDescriptor fd,
 462                      InetAddress addr, int port) throws IOException
 463     {
 464         boolean preferIPv6 = isIPv6Available() &&
 465             (family != StandardProtocolFamily.INET);
 466         if (addr.isLinkLocalAddress()) {
 467             addr = IPAddressUtil.toScopedAddress(addr);
 468         }
 469         bind0(fd, preferIPv6, exclusiveBind, addr, port);
 470     }
 471 
 472     private static native void bind0(FileDescriptor fd, boolean preferIPv6,
 473                                      boolean useExclBind, InetAddress addr,
 474                                      int port)
 475         throws IOException;
 476 
 477     static native void listen(FileDescriptor fd, int backlog) throws IOException;
 478 
 479     static int connect(FileDescriptor fd, InetAddress remote, int remotePort)
 480         throws IOException
 481     {
 482         return connect(UNSPEC, fd, remote, remotePort);
 483     }
 484 
 485     static int connect(ProtocolFamily family, FileDescriptor fd, InetAddress remote, int remotePort)
 486         throws IOException
 487     {
 488         if (remote.isLinkLocalAddress()) {
 489             remote = IPAddressUtil.toScopedAddress(remote);
 490         }
 491         boolean preferIPv6 = isIPv6Available() &&
 492             (family != StandardProtocolFamily.INET);
 493         return connect0(preferIPv6, fd, remote, remotePort);
 494     }
 495 
 496     private static native int connect0(boolean preferIPv6,
 497                                        FileDescriptor fd,
 498                                        InetAddress remote,
 499                                        int remotePort)
 500         throws IOException;
 501 
 502     public static native int accept(FileDescriptor fd,
 503                                     FileDescriptor newfd,
 504                                     InetSocketAddress[] isaa)
 505         throws IOException;
 506 
 507     public static final int SHUT_RD = 0;
 508     public static final int SHUT_WR = 1;
 509     public static final int SHUT_RDWR = 2;
 510 




  33 import java.net.InetSocketAddress;
  34 import java.net.NetworkInterface;
  35 import java.net.ProtocolFamily;
  36 import java.net.SocketAddress;
  37 import java.net.SocketException;
  38 import java.net.SocketOption;
  39 import java.net.StandardProtocolFamily;
  40 import java.net.StandardSocketOptions;
  41 import java.net.UnknownHostException;
  42 import java.nio.channels.AlreadyBoundException;
  43 import java.nio.channels.ClosedChannelException;
  44 import java.nio.channels.NotYetBoundException;
  45 import java.nio.channels.NotYetConnectedException;
  46 import java.nio.channels.UnresolvedAddressException;
  47 import java.nio.channels.UnsupportedAddressTypeException;
  48 import java.security.AccessController;
  49 import java.security.PrivilegedAction;
  50 import java.util.Enumeration;
  51 
  52 import sun.net.ext.ExtendedSocketOptions;

  53 import sun.security.action.GetPropertyAction;
  54 
  55 public class Net {
  56 
  57     private Net() { }
  58 
  59     // unspecified protocol family
  60     static final ProtocolFamily UNSPEC = new ProtocolFamily() {
  61         public String name() {
  62             return "UNSPEC";
  63         }
  64     };
  65 
  66     // set to true if exclusive binding is on for Windows
  67     private static final boolean exclusiveBind;
  68 
  69     // set to true if the fast tcp loopback should be enabled on Windows
  70     private static final boolean fastLoopback;
  71 
  72     // -- Miscellaneous utilities --


 445 
 446     static FileDescriptor serverSocket(boolean stream) {
 447         return IOUtil.newFD(socket0(isIPv6Available(), stream, true, fastLoopback));
 448     }
 449 
 450     // Due to oddities SO_REUSEADDR on windows reuse is ignored
 451     private static native int socket0(boolean preferIPv6, boolean stream, boolean reuse,
 452                                       boolean fastLoopback);
 453 
 454     public static void bind(FileDescriptor fd, InetAddress addr, int port)
 455         throws IOException
 456     {
 457         bind(UNSPEC, fd, addr, port);
 458     }
 459 
 460     static void bind(ProtocolFamily family, FileDescriptor fd,
 461                      InetAddress addr, int port) throws IOException
 462     {
 463         boolean preferIPv6 = isIPv6Available() &&
 464             (family != StandardProtocolFamily.INET);



 465         bind0(fd, preferIPv6, exclusiveBind, addr, port);
 466     }
 467 
 468     private static native void bind0(FileDescriptor fd, boolean preferIPv6,
 469                                      boolean useExclBind, InetAddress addr,
 470                                      int port)
 471         throws IOException;
 472 
 473     static native void listen(FileDescriptor fd, int backlog) throws IOException;
 474 
 475     static int connect(FileDescriptor fd, InetAddress remote, int remotePort)
 476         throws IOException
 477     {
 478         return connect(UNSPEC, fd, remote, remotePort);
 479     }
 480 
 481     static int connect(ProtocolFamily family, FileDescriptor fd, InetAddress remote, int remotePort)
 482         throws IOException
 483     {



 484         boolean preferIPv6 = isIPv6Available() &&
 485             (family != StandardProtocolFamily.INET);
 486         return connect0(preferIPv6, fd, remote, remotePort);
 487     }
 488 
 489     private static native int connect0(boolean preferIPv6,
 490                                        FileDescriptor fd,
 491                                        InetAddress remote,
 492                                        int remotePort)
 493         throws IOException;
 494 
 495     public static native int accept(FileDescriptor fd,
 496                                     FileDescriptor newfd,
 497                                     InetSocketAddress[] isaa)
 498         throws IOException;
 499 
 500     public static final int SHUT_RD = 0;
 501     public static final int SHUT_WR = 1;
 502     public static final int SHUT_RDWR = 2;
 503 


< prev index next >