src/solaris/classes/sun/nio/ch/InheritedChannel.java

Print this page




 148         // 2. Allows streams based on file descriptor 0 to co-exist with
 149         //    the channel (closing one doesn't impact the other)
 150 
 151         int fdVal = dup(0);
 152 
 153         // Examine the file descriptor - if it's not a socket then we don't
 154         // create a channel so we release the file descriptor.
 155 
 156         int st;
 157         st = soType0(fdVal);
 158         if (st != SOCK_STREAM && st != SOCK_DGRAM) {
 159             close0(fdVal);
 160             return null;
 161         }
 162 
 163 
 164         // Next we create a FileDescriptor for the dup'ed file descriptor
 165         // Have to use reflection and also make assumption on how FD
 166         // is implemented.
 167 
 168         Class paramTypes[] = { int.class };
 169         Constructor<?> ctr = Reflect.lookupConstructor("java.io.FileDescriptor",
 170                                                        paramTypes);
 171         Object args[] = { new Integer(fdVal) };
 172         FileDescriptor fd = (FileDescriptor)Reflect.invoke(ctr, args);
 173 
 174 
 175         // Now create the channel. If the socket is a streams socket then
 176         // we see if tthere is a peer (ie: connected). If so, then we
 177         // create a SocketChannel, otherwise a ServerSocketChannel.
 178         // If the socket is a datagram socket then create a DatagramChannel
 179 
 180         SelectorProvider provider = SelectorProvider.provider();
 181         assert provider instanceof sun.nio.ch.SelectorProviderImpl;
 182 
 183         Channel c;
 184         if (st == SOCK_STREAM) {
 185             InetAddress ia = peerAddress0(fdVal);
 186             if (ia == null) {
 187                c = new InheritedServerSocketChannelImpl(provider, fd);
 188             } else {




 148         // 2. Allows streams based on file descriptor 0 to co-exist with
 149         //    the channel (closing one doesn't impact the other)
 150 
 151         int fdVal = dup(0);
 152 
 153         // Examine the file descriptor - if it's not a socket then we don't
 154         // create a channel so we release the file descriptor.
 155 
 156         int st;
 157         st = soType0(fdVal);
 158         if (st != SOCK_STREAM && st != SOCK_DGRAM) {
 159             close0(fdVal);
 160             return null;
 161         }
 162 
 163 
 164         // Next we create a FileDescriptor for the dup'ed file descriptor
 165         // Have to use reflection and also make assumption on how FD
 166         // is implemented.
 167 
 168         Class<?> paramTypes[] = { int.class };
 169         Constructor<?> ctr = Reflect.lookupConstructor("java.io.FileDescriptor",
 170                                                        paramTypes);
 171         Object args[] = { new Integer(fdVal) };
 172         FileDescriptor fd = (FileDescriptor)Reflect.invoke(ctr, args);
 173 
 174 
 175         // Now create the channel. If the socket is a streams socket then
 176         // we see if tthere is a peer (ie: connected). If so, then we
 177         // create a SocketChannel, otherwise a ServerSocketChannel.
 178         // If the socket is a datagram socket then create a DatagramChannel
 179 
 180         SelectorProvider provider = SelectorProvider.provider();
 181         assert provider instanceof sun.nio.ch.SelectorProviderImpl;
 182 
 183         Channel c;
 184         if (st == SOCK_STREAM) {
 185             InetAddress ia = peerAddress0(fdVal);
 186             if (ia == null) {
 187                c = new InheritedServerSocketChannelImpl(provider, fd);
 188             } else {