< prev index next >

src/java.base/unix/classes/sun/nio/ch/InheritedChannel.java

Print this page




 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[] = { Integer.valueOf(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 {
 189                int port = peerPort0(fdVal);
 190                assert port > 0;
 191                InetSocketAddress isa = new InetSocketAddress(ia, port);
 192                c = new InheritedSocketChannelImpl(provider, fd, isa);
 193             }
 194         } else {
 195             c = new InheritedDatagramChannelImpl(provider, fd);

 196         }
 197         return c;
 198     }
 199 
 200     private static boolean haveChannel = false;
 201     private static Channel channel = null;
 202 
 203     /*
 204      * Returns a Channel representing the inherited channel if the
 205      * inherited channel is a stream connected to a network socket.
 206      */
 207     public static synchronized Channel getChannel() throws IOException {
 208         if (devnull < 0) {
 209             devnull = open0("/dev/null", O_RDWR);
 210         }
 211 
 212         // If we don't have the channel try to create it
 213         if (!haveChannel) {
 214             channel = createChannel();
 215             haveChannel = true;




 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[] = { Integer.valueOf(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         try {
 185             if (st == SOCK_STREAM) {
 186                 InetAddress ia = peerAddress0(fdVal);
 187                 if (ia == null) {
 188                     c = new InheritedServerSocketChannelImpl(provider, fd);
 189                 } else {
 190                     int port = peerPort0(fdVal);
 191                     assert port > 0;
 192                     InetSocketAddress isa = new InetSocketAddress(ia, port);
 193                     c = new InheritedSocketChannelImpl(provider, fd, isa);
 194                 }
 195             } else {
 196                 c = new InheritedDatagramChannelImpl(provider, fd);



 197             }
 198         } catch (Exception e) {
 199             close0(fdVal);
 200             throw e;
 201         }
 202         return c;
 203     }
 204 
 205     private static boolean haveChannel = false;
 206     private static Channel channel = null;
 207 
 208     /*
 209      * Returns a Channel representing the inherited channel if the
 210      * inherited channel is a stream connected to a network socket.
 211      */
 212     public static synchronized Channel getChannel() throws IOException {
 213         if (devnull < 0) {
 214             devnull = open0("/dev/null", O_RDWR);
 215         }
 216 
 217         // If we don't have the channel try to create it
 218         if (!haveChannel) {
 219             channel = createChannel();
 220             haveChannel = true;


< prev index next >