/** * 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; }
public ChannelFD getWrapperFromFileno(int fileno) { ChannelFD fd = filenoMap.get(fileno); // This is a hack to get around stale ChannelFD that are closed when a descriptor is reused. // It appears to happen for openpty, and in theory could happen for any IO call that produces // a new descriptor. if (fd != null && !fd.ch.isOpen() && !isFake(fileno)) { FileStat stat = posix.allocateStat(); if (posix.fstat(fileno, stat) >= 0) { // found ChannelFD is closed, but actual fileno is open; clear it. filenoMap.remove(fileno); fd = null; } } return fd; }
public ChannelFD getWrapperFromFileno(int fileno) { ChannelFD fd = filenoMap.get(fileno); // This is a hack to get around stale ChannelFD that are closed when a descriptor is reused. // It appears to happen for openpty, and in theory could happen for any IO call that produces // a new descriptor. if (fd != null && !fd.ch.isOpen() && !isFake(fileno)) { FileStat stat = posix.allocateStat(); if (posix.fstat(fileno, stat) >= 0) { // found ChannelFD is closed, but actual fileno is open; clear it. filenoMap.remove(fileno); fd = null; } } return fd; }
if (FilenoUtil.isFake(fd)) { throw runtime.newTypeError("file descriptor is not native");
if (FilenoUtil.isFake(fd)) { throw runtime.newTypeError("file descriptor is not native");
if (!FilenoUtil.isFake(fileno)) {
if (!FilenoUtil.isFake(fileno)) {