@Deprecated public static int getFilenoFromChannel(Channel channel) { return FilenoUtil.filenoFrom(channel); } }
@Deprecated public static int getFilenoFromChannel(Channel channel) { return FilenoUtil.filenoFrom(channel); } }
private void initFileno() { realFileno = FilenoUtil.filenoFrom(ch); if (realFileno == -1) { fakeFileno = filenoUtil.getNewFileno(); } else { fakeFileno = -1; } }
private static int unwrapDripStream(Object stream) { if (stream.getClass().getName().startsWith("org.flatland.drip.Switchable")) { try { FileDescriptor fd = (FileDescriptor) stream.getClass().getMethod("getFD").invoke(stream); return FilenoUtil.filenoFrom(fd); } catch (NoSuchMethodException nsme) { nsme.printStackTrace(System.err); } catch (IllegalAccessException iae) { iae.printStackTrace(System.err); } catch (InvocationTargetException ite) { ite.printStackTrace(System.err); } } return -1; }
private static int getFilenoUsingReflection(Channel channel) { if (ReflectiveAccess.FILE_DESCRIPTOR_FD != null) { return filenoFrom(getDescriptorFromChannel(channel)); } return -1; }
private void initFileno() { realFileno = FilenoUtil.filenoFrom(ch); if (realFileno == -1) { fakeFileno = filenoUtil.getNewFileno(); } else { fakeFileno = -1; } }
private static int getFilenoUsingReflection(Channel channel) { if (ReflectiveAccess.FILE_DESCRIPTOR_FD != null) { return filenoFrom(getDescriptorFromChannel(channel)); } return -1; }
private static int unwrapDripStream(Object stream) { if (stream.getClass().getName().startsWith("org.flatland.drip.Switchable")) { try { FileDescriptor fd = (FileDescriptor) stream.getClass().getMethod("getFD").invoke(stream); return FilenoUtil.filenoFrom(fd); } catch (NoSuchMethodException nsme) { nsme.printStackTrace(System.err); } catch (IllegalAccessException iae) { iae.printStackTrace(System.err); } catch (InvocationTargetException ite) { ite.printStackTrace(System.err); } } return -1; }
fileno = FilenoUtil.filenoFrom(channel); } else if (stream instanceof InputStream) { InputStream unwrappedStream = ChannelHelper.unwrapFilterInputStream((InputStream) stream); if (unwrappedStream instanceof FileInputStream) { fileno = FilenoUtil.filenoFrom(((FileInputStream) unwrappedStream).getChannel()); fileno = FilenoUtil.filenoFrom(((FileOutputStream) unwrappedStream).getChannel());
fileno = FilenoUtil.filenoFrom(channel); } else if (stream instanceof InputStream) { InputStream unwrappedStream = ChannelHelper.unwrapFilterInputStream((InputStream) stream); if (unwrappedStream instanceof FileInputStream) { fileno = FilenoUtil.filenoFrom(((FileInputStream) unwrappedStream).getChannel()); fileno = FilenoUtil.filenoFrom(((FileOutputStream) unwrappedStream).getChannel());
public Channel[] pipe() { clear(); try { Pipe pipe = Pipe.open(); Channel source = pipe.source(), sink = pipe.sink(); if (posix.isNative() && !Platform.IS_WINDOWS) { // set cloexec if possible int read = FilenoUtil.filenoFrom(source); int write = FilenoUtil.filenoFrom(sink); setCloexec(read, true); setCloexec(write, true); } return new Channel[]{source, sink}; } catch (IOException ioe) { errno = Helpers.errnoFromException(ioe); return null; } }
public Channel[] pipe() { clear(); try { Pipe pipe = Pipe.open(); Channel source = pipe.source(), sink = pipe.sink(); if (posix.isNative() && !Platform.IS_WINDOWS) { // set cloexec if possible int read = FilenoUtil.filenoFrom(source); int write = FilenoUtil.filenoFrom(sink); setCloexec(read, true); setCloexec(write, true); } return new Channel[]{source, sink}; } catch (IOException ioe) { errno = Helpers.errnoFromException(ioe); return null; } }
/** * Build a set of mode flags using the specified channel's actual capabilities. * * @param channel the channel to examine for capabilities * @return the mode flags */ public static int oflagsFrom(POSIX posix, Channel channel) { int mode; int fileno = FilenoUtil.filenoFrom(channel); if (FilenoUtil.isFake(fileno) || !posix.isNative() || Platform.IS_WINDOWS) { // channel doesn't have a real fileno; best we can do is go off the Java type if (channel instanceof ReadableByteChannel) { if (channel instanceof WritableByteChannel) { mode = RDWR; } else { mode = RDONLY; } } else if (channel instanceof WritableByteChannel) { mode = WRONLY; } else { // FIXME: I don't like this mode = RDWR; } } else { // real fileno, we can use fcntl mode = posix.fcntl(fileno, Fcntl.F_GETFL); } return mode; }
/** * Build a set of mode flags using the specified channel's actual capabilities. * * @param channel the channel to examine for capabilities * @return the mode flags */ public static int oflagsFrom(POSIX posix, Channel channel) { int mode; int fileno = FilenoUtil.filenoFrom(channel); if (FilenoUtil.isFake(fileno) || !posix.isNative() || Platform.IS_WINDOWS) { // channel doesn't have a real fileno; best we can do is go off the Java type if (channel instanceof ReadableByteChannel) { if (channel instanceof WritableByteChannel) { mode = RDWR; } else { mode = RDONLY; } } else if (channel instanceof WritableByteChannel) { mode = WRONLY; } else { // FIXME: I don't like this mode = RDWR; } } else { // real fileno, we can use fcntl mode = posix.fcntl(fileno, Fcntl.F_GETFL); } return mode; }
@JRubyMethod(name = "sysaccept") public IRubyObject sysaccept(ThreadContext context) { Ruby runtime = context.runtime; try { RubyThread thread = context.getThread(); while (true) { boolean ready = thread.select(this, SelectionKey.OP_ACCEPT); if (!ready) { // we were woken up without being selected...poll for thread events and go back to sleep context.pollThreadEvents(); } else { SocketChannel connected = getServerSocketChannel().accept(); if (connected == null) continue; connected.finishConnect(); return runtime.newFixnum(FilenoUtil.filenoFrom(connected)); } } } catch(IOException e) { throw runtime.newIOErrorFromException(e); } }
@JRubyMethod(name = "sysaccept") public IRubyObject sysaccept(ThreadContext context) { Ruby runtime = context.runtime; try { RubyThread thread = context.getThread(); while (true) { boolean ready = thread.select(this, SelectionKey.OP_ACCEPT); if (!ready) { // we were woken up without being selected...poll for thread events and go back to sleep context.pollThreadEvents(); } else { SocketChannel connected = getServerSocketChannel().accept(); if (connected == null) continue; connected.finishConnect(); return runtime.newFixnum(FilenoUtil.filenoFrom(connected)); } } } catch(IOException e) { throw runtime.newIOErrorFromException(e); } }