< prev index next >

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

Print this page
rev 55750 : UDS support, temporary commit

*** 36,45 **** --- 36,46 ---- import java.net.SocketAddress; import java.net.SocketException; import java.net.SocketOption; import java.net.StandardProtocolFamily; import java.net.StandardSocketOptions; + import java.net.UnixSocketAddress; import java.net.UnknownHostException; import java.nio.channels.AlreadyBoundException; import java.nio.channels.ClosedChannelException; import java.nio.channels.NotYetBoundException; import java.nio.channels.NotYetConnectedException;
*** 437,459 **** --- 438,484 ---- static FileDescriptor socket(boolean stream) throws IOException { return socket(UNSPEC, stream); } static FileDescriptor socket(ProtocolFamily family, boolean stream) throws IOException { + if (family == StandardProtocolFamily.UNIX) { + return IOUtil.newFD(socket1(stream)); + } else { boolean preferIPv6 = isIPv6Available() && (family != StandardProtocolFamily.INET); return IOUtil.newFD(socket0(preferIPv6, stream, false, fastLoopback)); } + } + + static FileDescriptor serverSocket(boolean stream, ProtocolFamily family) { + if (family == StandardProtocolFamily.UNIX) { + return IOUtil.newFD(socket1(stream)); + } else { + return serverSocket(stream); + } + } static FileDescriptor serverSocket(boolean stream) { return IOUtil.newFD(socket0(isIPv6Available(), stream, true, fastLoopback)); } // Due to oddities SO_REUSEADDR on windows reuse is ignored private static native int socket0(boolean preferIPv6, boolean stream, boolean reuse, boolean fastLoopback); + // TODO: rename, refactor, support maybe also SOCK_SEQPACKET, support reuse (delete socket file if exists)? + private static native int socket1(boolean stream); + + public static void bind(FileDescriptor fd, UnixSocketAddress addr) + throws IOException + { + bind1(fd, addr.getPathBytes()); + } + + // TODO: rename, UnixSocketAddress object instead of byte array? + private static native void bind1(FileDescriptor fd, byte[] addr) throws IOException; + public static void bind(FileDescriptor fd, InetAddress addr, int port) throws IOException { bind(UNSPEC, fd, addr, port); }
*** 480,489 **** --- 505,520 ---- throws IOException { return connect(UNSPEC, fd, remote, remotePort); } + static int connect(FileDescriptor fd, UnixSocketAddress remote) + throws IOException + { + return connect1(fd, remote.getPathBytes()); + } + static int connect(ProtocolFamily family, FileDescriptor fd, InetAddress remote, int remotePort) throws IOException { if (remote.isLinkLocalAddress()) { remote = IPAddressUtil.toScopedAddress(remote);
*** 497,509 **** FileDescriptor fd, InetAddress remote, int remotePort) throws IOException; ! public static native int accept(FileDescriptor fd, FileDescriptor newfd, InetSocketAddress[] isaa) throws IOException; public static final int SHUT_RD = 0; public static final int SHUT_WR = 1; public static final int SHUT_RDWR = 2; --- 528,556 ---- FileDescriptor fd, InetAddress remote, int remotePort) throws IOException; ! private static native int connect1(FileDescriptor fd, byte[] remote) ! throws IOException; ! ! public static int accept(FileDescriptor fd, FileDescriptor newfd, InetSocketAddress[] isaa) + throws IOException { + + SocketAddress[] array = new SocketAddress[isaa.length]; + int result = accept(fd, newfd, array); + for (int i = 0; i < isaa.length; i++) { + isaa[i] = (InetSocketAddress) array[i]; + } + return result; + } + + public static native int accept(FileDescriptor fd, + FileDescriptor newfd, + SocketAddress[] isaa) throws IOException; public static final int SHUT_RD = 0; public static final int SHUT_WR = 1; public static final int SHUT_RDWR = 2;
*** 520,529 **** --- 567,579 ---- throws IOException { return new InetSocketAddress(localInetAddress(fd), localPort(fd)); } + public static native SocketAddress localSocketAddress(FileDescriptor fd) + throws IOException; + private static native int remotePort(FileDescriptor fd) throws IOException; private static native InetAddress remoteInetAddress(FileDescriptor fd) throws IOException;
< prev index next >