Top Description Inners Fields Constructors Methods
org.jruby.util.io

public Class PosixShim

extends Object
Class Inheritance
Imports
java.io.Closeable, .IOException, java.nio.ByteBuffer, java.nio.channels.Channel, .Channels, .FileLock, .NotYetConnectedException, .OverlappingFileLockException, .Pipe, jnr.constants.platform.Errno, .Fcntl, jnr.posix.FileStat, .POSIX, org.jruby.Ruby, org.jruby.ext.fcntl.FcntlLibrary, org.jruby.platform.Platform, org.jruby.runtime.Helpers, org.jruby.util.JRubyFile, .ResourceException

Representations of as many native posix functions as possible applied to an NIO channel

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class
public static class
public static interface

Field Summary

Modifier and TypeField and Description
private static int
_cachedUmask

The last umask we set

private static final Object
_umaskLock

An object to synchronize calls to umask

public String
errmsg

The recommended error message, if any.

private final ThreadLocal<Errno>
public Throwable
error

The last Throwable exception raised by a call.

private static final int
public static final int
public static final int
public static final int
public static final int
private static final int
private final POSIX
posix

The POSIX instance to use for native calls

private final Ruby
runtime

The current runtime

public static final int
public static final int
public static final int
public static final PosixShim.WaitMacros

Constructor Summary

AccessConstructor and Description
public
PosixShim(Ruby runtime)

Method Summary

Modifier and TypeMethod and Description
private boolean
checkForBlocking(ChannelFD fd, boolean nonblock)

private int
checkSharedExclusive(ChannelFD fd, int lockMode)

private void
public int
public int
close(Closeable closeable)

public int
dup2(ChannelFD filedes, ChannelFD filedes2)

public int
fcntlGetFD(int fd)

public int
fcntlSetFD(int fd, int flags)

public int
flock(ChannelFD fd, int lockMode)

public int
ftruncate(ChannelFD fd, long pos)

public Errno
getErrno()

The appropriate errno value for the last thrown error, if any.

private int
lock(ChannelFD fd, boolean exclusive)

private static int
lockFailedReturn(int lockMode)

private static boolean
lockStateChanges(FileLock lock, int lockMode)

public long
lseek(ChannelFD fd, long offset, int type)

public Channel
open(String cwd, String path, int flags, int perm)

public Channel
open(String cwd, String path, ModeFlags flags, int perm)

public Channel
open(String cwd, String path, ModeFlags flags, int perm, ClassLoader classLoader)
Deprecated

private int
performRead(ChannelFD fd, ByteBuffer buffer, boolean nonblock)

public Channel[]
pipe()

public int
read(ChannelFD fd, byte[] target, int offset, int length, boolean nonblock)

public int
read(ChannelFD fd, ByteBuffer buffer, int offset, int length, boolean nonblock)

public int
setCloexec(int fd, boolean cloexec)

public void
setErrno(Errno errno)

public long
private int
tryLock(ChannelFD fd, boolean exclusive)

public static int
umask(POSIX posix)

Joy of POSIX, only way to get the umask is to set the umask, then set it back.

public static int
umask(POSIX posix, int newMask)

private int
public int
write(ChannelFD fd, byte[] bytes, int offset, int length, boolean nonblock)

public int
write(ChannelFD fd, ByteBuffer buffer, int offset, int length, boolean nonblock)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

_cachedUmaskback to summary
private static int _cachedUmask

The last umask we set

_umaskLockback to summary
private static final Object _umaskLock

An object to synchronize calls to umask

errmsgback to summary
public String errmsg

The recommended error message, if any.

errnoback to summary
private final ThreadLocal<Errno> errno
errorback to summary
public Throwable error

The last Throwable exception raised by a call.

JAVA_EOFback to summary
private static final int JAVA_EOF
LOCK_EXback to summary
public static final int LOCK_EX
LOCK_NBback to summary
public static final int LOCK_NB
LOCK_SHback to summary
public static final int LOCK_SH
LOCK_UNback to summary
public static final int LOCK_UN
NATIVE_EOFback to summary
private static final int NATIVE_EOF
posixback to summary
private final POSIX posix

The POSIX instance to use for native calls

runtimeback to summary
private final Ruby runtime

The current runtime

SEEK_CURback to summary
public static final int SEEK_CUR
SEEK_ENDback to summary
public static final int SEEK_END
SEEK_SETback to summary
public static final int SEEK_SET
WAIT_MACROSback to summary
public static final PosixShim.WaitMacros WAIT_MACROS

Constructor Detail

PosixShimback to summary
public PosixShim(Ruby runtime)

Method Detail

checkForBlockingback to summary
private boolean checkForBlocking(ChannelFD fd, boolean nonblock) throws IOException
checkSharedExclusiveback to summary
private int checkSharedExclusive(ChannelFD fd, int lockMode)
clearback to summary
private void clear()
closeback to summary
public int close(ChannelFD fd)
closeback to summary
public int close(Closeable closeable)
dup2back to summary
public int dup2(ChannelFD filedes, ChannelFD filedes2)
fcntlGetFDback to summary
public int fcntlGetFD(int fd)
fcntlSetFDback to summary
public int fcntlSetFD(int fd, int flags)
flockback to summary
public int flock(ChannelFD fd, int lockMode)
ftruncateback to summary
public int ftruncate(ChannelFD fd, long pos)
getErrnoback to summary
public Errno getErrno()

The appropriate errno value for the last thrown error, if any.

lockback to summary
private int lock(ChannelFD fd, boolean exclusive) throws IOException
lockFailedReturnback to summary
private static int lockFailedReturn(int lockMode)
lockStateChangesback to summary
private static boolean lockStateChanges(FileLock lock, int lockMode)
lseekback to summary
public long lseek(ChannelFD fd, long offset, int type)
openback to summary
public Channel open(String cwd, String path, int flags, int perm)
openback to summary
public Channel open(String cwd, String path, ModeFlags flags, int perm)
openback to summary
public Channel open(String cwd, String path, ModeFlags flags, int perm, ClassLoader classLoader)

Deprecated

Annotations
@Deprecated
performReadback to summary
private int performRead(ChannelFD fd, ByteBuffer buffer, boolean nonblock) throws IOException
pipeback to summary
public Channel[] pipe()
readback to summary
public int read(ChannelFD fd, byte[] target, int offset, int length, boolean nonblock)
readback to summary
public int read(ChannelFD fd, ByteBuffer buffer, int offset, int length, boolean nonblock)
setCloexecback to summary
public int setCloexec(int fd, boolean cloexec)
setErrnoback to summary
public void setErrno(Errno errno)
sizeback to summary
public long size(ChannelFD fd)
tryLockback to summary
private int tryLock(ChannelFD fd, boolean exclusive) throws IOException
umaskback to summary
public static int umask(POSIX posix)

Joy of POSIX, only way to get the umask is to set the umask, then set it back. That's unsafe in a threaded program. We minimize but may not totally remove this race by caching the obtained or previously set (see umask() above) umask and using that as the initial set value which, cross fingers, is a no-op. The cache access is then synchronized.

Todo

Better?

umaskback to summary
public static int umask(POSIX posix, int newMask)
unlockback to summary
private int unlock(ChannelFD fd) throws IOException
writeback to summary
public int write(ChannelFD fd, byte[] bytes, int offset, int length, boolean nonblock)
writeback to summary
public int write(ChannelFD fd, ByteBuffer buffer, int offset, int length, boolean nonblock)
org.jruby.util.io back to summary

public Class PosixShim.BSDWaitMacros

extends Object
implements WaitMacros
Class Inheritance
All Implemented Interfaces
org.jruby.util.io.PosixShim.WaitMacros

Field Summary

Modifier and TypeField and Description
public final long
public final long

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public long
_WSTATUS(long status)

public boolean
public int
public boolean
public boolean
public boolean
public int
public int
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

_WSTOPPEDback to summary
public final long _WSTOPPED
WCOREFLAGback to summary
public final long WCOREFLAG

Constructor Detail

BSDWaitMacrosback to summary
public BSDWaitMacros()

Method Detail

_WSTATUSback to summary
public long _WSTATUS(long status)
WCOREDUMPback to summary
public boolean WCOREDUMP(long status)

Implements org.jruby.util.io.PosixShim.WaitMacros.WCOREDUMP.

WEXITSTATUSback to summary
public int WEXITSTATUS(long status)

Implements org.jruby.util.io.PosixShim.WaitMacros.WEXITSTATUS.

WIFEXITEDback to summary
public boolean WIFEXITED(long status)

Implements org.jruby.util.io.PosixShim.WaitMacros.WIFEXITED.

WIFSIGNALEDback to summary
public boolean WIFSIGNALED(long status)

Implements org.jruby.util.io.PosixShim.WaitMacros.WIFSIGNALED.

WIFSTOPPEDback to summary
public boolean WIFSTOPPED(long status)

Implements org.jruby.util.io.PosixShim.WaitMacros.WIFSTOPPED.

WSTOPSIGback to summary
public int WSTOPSIG(long status)

Implements org.jruby.util.io.PosixShim.WaitMacros.WSTOPSIG.

WTERMSIGback to summary
public int WTERMSIG(long status)

Implements org.jruby.util.io.PosixShim.WaitMacros.WTERMSIG.

org.jruby.util.io back to summary

public Class PosixShim.LinuxWaitMacros

extends Object
implements WaitMacros
Class Inheritance
All Implemented Interfaces
org.jruby.util.io.PosixShim.WaitMacros

Field Summary

Modifier and TypeField and Description
private static int
private static final int

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
private int
__W_EXITCODE(int ret, int sig)

private int
__W_STOPCODE(int sig)

private int
__WAIT_INT(long status)

private boolean
__WCOREDUMP(long status)

private int
__WEXITSTATUS(long status)

private boolean
__WIFEXITED(long status)

private boolean
__WIFSIGNALED(long status)

private boolean
__WIFSTOPPED(long status)

private int
__WSTOPSIG(long status)

private int
__WTERMSIG(long status)

public boolean
public int
public boolean
public boolean
public boolean
public int
public int
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

__W_CONTINUEDback to summary
private static int __W_CONTINUED
__WCOREFLAGback to summary
private static final int __WCOREFLAG

Constructor Detail

LinuxWaitMacrosback to summary
public LinuxWaitMacros()

Method Detail

__W_EXITCODEback to summary
private int __W_EXITCODE(int ret, int sig)
__W_STOPCODEback to summary
private int __W_STOPCODE(int sig)
__WAIT_INTback to summary
private int __WAIT_INT(long status)
__WCOREDUMPback to summary
private boolean __WCOREDUMP(long status)
__WEXITSTATUSback to summary
private int __WEXITSTATUS(long status)
__WIFEXITEDback to summary
private boolean __WIFEXITED(long status)
__WIFSIGNALEDback to summary
private boolean __WIFSIGNALED(long status)
__WIFSTOPPEDback to summary
private boolean __WIFSTOPPED(long status)
__WSTOPSIGback to summary
private int __WSTOPSIG(long status)
__WTERMSIGback to summary
private int __WTERMSIG(long status)
WCOREDUMPback to summary
public boolean WCOREDUMP(long status)

Implements org.jruby.util.io.PosixShim.WaitMacros.WCOREDUMP.

WEXITSTATUSback to summary
public int WEXITSTATUS(long status)

Implements org.jruby.util.io.PosixShim.WaitMacros.WEXITSTATUS.

WIFEXITEDback to summary
public boolean WIFEXITED(long status)

Implements org.jruby.util.io.PosixShim.WaitMacros.WIFEXITED.

WIFSIGNALEDback to summary
public boolean WIFSIGNALED(long status)

Implements org.jruby.util.io.PosixShim.WaitMacros.WIFSIGNALED.

WIFSTOPPEDback to summary
public boolean WIFSTOPPED(long status)

Implements org.jruby.util.io.PosixShim.WaitMacros.WIFSTOPPED.

WSTOPSIGback to summary
public int WSTOPSIG(long status)

Implements org.jruby.util.io.PosixShim.WaitMacros.WSTOPSIG.

WTERMSIGback to summary
public int WTERMSIG(long status)

Implements org.jruby.util.io.PosixShim.WaitMacros.WTERMSIG.

org.jruby.util.io back to summary

public Interface PosixShim.WaitMacros

Known Direct Implementers
org.jruby.util.io.PosixShim.BSDWaitMacros, org.jruby.util.io.PosixShim.LinuxWaitMacros

Method Summary

Modifier and TypeMethod and Description
public boolean
WCOREDUMP(long status)

public int
WEXITSTATUS(long status)

public boolean
WIFEXITED(long status)

public boolean
WIFSIGNALED(long status)

public boolean
WIFSTOPPED(long status)

public int
WSTOPSIG(long status)

public int
WTERMSIG(long status)

Method Detail

WCOREDUMPback to summary
public boolean WCOREDUMP(long status)
WEXITSTATUSback to summary
public int WEXITSTATUS(long status)
WIFEXITEDback to summary
public boolean WIFEXITED(long status)
WIFSIGNALEDback to summary
public boolean WIFSIGNALED(long status)
WIFSTOPPEDback to summary
public boolean WIFSTOPPED(long status)
WSTOPSIGback to summary
public int WSTOPSIG(long status)
WTERMSIGback to summary
public int WTERMSIG(long status)