src/java.base/unix/classes/sun/nio/ch/InheritedChannel.java
branchunixdomainchannels
changeset 58988 b88e23c84b23
parent 58981 5c79956cc7d7
equal deleted inserted replaced
58981:5c79956cc7d7 58988:b88e23c84b23
    37 import java.nio.ByteBuffer;
    37 import java.nio.ByteBuffer;
    38 import java.nio.channels.Channel;
    38 import java.nio.channels.Channel;
    39 import java.nio.channels.SocketChannel;
    39 import java.nio.channels.SocketChannel;
    40 import java.nio.channels.ServerSocketChannel;
    40 import java.nio.channels.ServerSocketChannel;
    41 import java.nio.channels.DatagramChannel;
    41 import java.nio.channels.DatagramChannel;
       
    42 import java.nio.channels.UnixDomainSocketAddress;
    42 import java.nio.channels.spi.SelectorProvider;
    43 import java.nio.channels.spi.SelectorProvider;
    43 
    44 
    44 class InheritedChannel {
    45 class InheritedChannel {
    45 
    46 
    46     // the "types" of socket returned by soType0
    47     // the "types" of socket returned by soType0
   100         }
   101         }
   101     }
   102     }
   102 
   103 
   103     public static class InheritedUnixSocketChannelImpl extends UnixDomainSocketChannelImpl {
   104     public static class InheritedUnixSocketChannelImpl extends UnixDomainSocketChannelImpl {
   104 
   105 
   105         InheritedUnixSocketChannelImpl(SelectorProvider sp, FileDescriptor fd)
   106         InheritedUnixSocketChannelImpl(SelectorProvider sp, 
   106             throws IOException
   107 				FileDescriptor fd,
   107         {
   108 				UnixDomainSocketAddress remote )
   108             super(sp, fd, true);
   109             throws IOException
       
   110         {
       
   111             super(sp, fd, remote);
   109         }
   112         }
   110 
   113 
   111         @Override
   114         @Override
   112         protected void implCloseSelectableChannel() throws IOException {
   115         protected void implCloseSelectableChannel() throws IOException {
   113             super.implCloseSelectableChannel();
   116             super.implCloseSelectableChannel();
   225             int family = addressFamily(fdVal);
   228             int family = addressFamily(fdVal);
   226             if (family == AF_UNKNOWN)
   229             if (family == AF_UNKNOWN)
   227                 return null;
   230                 return null;
   228             if (family == AF_UNIX) {
   231             if (family == AF_UNIX) {
   229                 if (isConnected(fdVal)) {
   232                 if (isConnected(fdVal)) {
   230                     return new InheritedUnixSocketChannelImpl(provider, fd);
   233 	            UnixDomainSocketAddress sa = peerAddressUnix(fdVal);
       
   234                     return new InheritedUnixSocketChannelImpl(provider, fd, sa);
   231                 } else {
   235                 } else {
   232                     return new InheritedUnixServerSocketChannelImpl(provider, fd);
   236                     return new InheritedUnixServerSocketChannelImpl(provider, fd);
   233                 }
   237                 }
   234             }
   238             }
   235             InetAddress ia = peerAddress0(fdVal);
   239             InetAddress ia = peerAddressInet(fdVal);
   236             if (ia == null) {
   240             if (ia == null) {
   237                c = new InheritedInetServerSocketChannelImpl(provider, fd);
   241                c = new InheritedInetServerSocketChannelImpl(provider, fd);
   238             } else {
   242             } else {
   239                int port = peerPort0(fdVal);
   243                int port = peerPort0(fdVal);
       
   244 
   240                assert port > 0;
   245                assert port > 0;
   241                InetSocketAddress isa = new InetSocketAddress(ia, port);
   246                InetSocketAddress isa = new InetSocketAddress(ia, port);
   242                c = new InheritedInetSocketChannelImpl(provider, fd, isa);
   247                c = new InheritedInetSocketChannelImpl(provider, fd, isa);
   243             }
   248             }
   244         } else {
   249         } else {
   281     private static native void dup2(int fd, int fd2) throws IOException;
   286     private static native void dup2(int fd, int fd2) throws IOException;
   282     private static native int open0(String path, int oflag) throws IOException;
   287     private static native int open0(String path, int oflag) throws IOException;
   283     private static native void close0(int fd) throws IOException;
   288     private static native void close0(int fd) throws IOException;
   284     private static native int soType0(int fd);
   289     private static native int soType0(int fd);
   285     private static native int addressFamily(int fd);
   290     private static native int addressFamily(int fd);
   286     private static native InetAddress peerAddress0(int fd);
   291     private static native InetAddress peerAddressInet(int fd);
       
   292     private static native UnixDomainSocketAddress peerAddressUnix(int fd);
   287     private static native int peerPort0(int fd);
   293     private static native int peerPort0(int fd);
   288 
   294 
   289     // return true if socket is connected to a peer
   295     // return true if socket is connected to a peer
   290     private static native boolean isConnected(int fd);
   296     private static native boolean isConnected(int fd);
   291 
   297