< prev index next >
src/java.base/unix/classes/sun/nio/ch/InheritedChannel.java
Print this page
rev 55750 : UDS support, temporary commit
@@ -28,10 +28,12 @@
import java.lang.reflect.Constructor;
import java.io.FileDescriptor;
import java.io.IOException;
import java.net.InetAddress;
import java.net.InetSocketAddress;
+import java.net.SocketAddress;
+import java.net.UnixSocketAddress;
import java.nio.channels.Channel;
import java.nio.channels.SocketChannel;
import java.nio.channels.ServerSocketChannel;
import java.nio.channels.DatagramChannel;
import java.nio.channels.spi.SelectorProvider;
@@ -75,11 +77,11 @@
*/
public static class InheritedSocketChannelImpl extends SocketChannelImpl {
InheritedSocketChannelImpl(SelectorProvider sp,
FileDescriptor fd,
- InetSocketAddress remote)
+ SocketAddress remote)
throws IOException
{
super(sp, fd, remote);
}
@@ -180,18 +182,20 @@
SelectorProvider provider = SelectorProvider.provider();
assert provider instanceof sun.nio.ch.SelectorProviderImpl;
Channel c;
if (st == SOCK_STREAM) {
- InetAddress ia = peerAddress0(fdVal);
- if (ia == null) {
+ SocketAddress sa = peerAddress0(fdVal);
+ if (sa == null) {
c = new InheritedServerSocketChannelImpl(provider, fd);
+ } else if (sa instanceof InetSocketAddress) {
+ c = new InheritedSocketChannelImpl(provider, fd, sa);
+ } else if (sa instanceof UnixSocketAddress) {
+ // TODO: custom class for unix sockets
+ c = new InheritedSocketChannelImpl(provider, fd, sa);
} else {
- int port = peerPort0(fdVal);
- assert port > 0;
- InetSocketAddress isa = new InetSocketAddress(ia, port);
- c = new InheritedSocketChannelImpl(provider, fd, isa);
+ throw new IllegalStateException("Unsupported socket type: " + sa.getClass().getName());
}
} else {
c = new InheritedDatagramChannelImpl(provider, fd);
}
return c;
@@ -230,12 +234,11 @@
private static native int dup(int fd) throws IOException;
private static native void dup2(int fd, int fd2) throws IOException;
private static native int open0(String path, int oflag) throws IOException;
private static native void close0(int fd) throws IOException;
private static native int soType0(int fd);
- private static native InetAddress peerAddress0(int fd);
- private static native int peerPort0(int fd);
+ private static native SocketAddress peerAddress0(int fd);
static {
IOUtil.load();
initIDs();
}
< prev index next >