public final class VMChannel extends Object
JikesRVM-specific implementation by Robin Garner and Filip Pizlo.
Note: JavaDoc from GNU Classpath has been deleted on methods where it would cause JavaDoc warnings.
Modifier and Type | Class and Description |
---|---|
(package private) static class |
VMChannel.Kind
An enumeration of possible kinds of channel.
|
private static class |
VMChannel.LocalByteArray
A thread-local store of non-moving buffers.
|
class |
VMChannel.State
A wrapper for a native file descriptor integer.
|
Modifier and Type | Field and Description |
---|---|
private VMChannel.Kind |
kind |
private static VMChannel.LocalByteArray |
localByteArray
Thread-local buffer for VM-side buffering of write calls
|
private static int |
MAX_STANDARD_FD
Don't do fast I/O for the standard file descriptors - these are used
for throwing exceptions, so may not be able to allocate.
|
private VMChannel.State |
nfd
Our reference implementation uses an integer to store the native
file descriptor.
|
Modifier and Type | Method and Description |
---|---|
VMChannel |
accept()
Accept an incoming connection, returning a new VMChannel, or null
if the channel is nonblocking and no connection is pending.
|
private static int |
accept(int native_fd) |
int |
available() |
private static int |
available(int native_fd) |
void |
close()
Close this socket.
|
(package private) static void |
close(int native_fd) |
boolean |
connect(InetSocketAddress saddr,
int timeout)
Connect the underlying socket file descriptor to the remote host.
|
private static boolean |
connect(int fd,
byte[] addr,
int port,
int timeout) |
private static boolean |
connect6(int fd,
byte[] addr,
int port,
int timeout) |
void |
disconnect()
Disconnect this channel, if it is a datagram socket.
|
private static void |
disconnect(int fd) |
boolean |
flush(boolean metadata) |
private static boolean |
flush(int fd,
boolean metadata) |
InetSocketAddress |
getLocalAddress() |
InetSocketAddress |
getPeerAddress() |
private static int |
getpeername(int fd,
ByteBuffer name) |
private static int |
getsockname(int fd,
ByteBuffer name) |
VMChannel.State |
getState() |
static VMChannel |
getStderr() |
static VMChannel |
getStdin() |
static VMChannel |
getStdout() |
private static void |
initIDs() |
void |
initSocket(boolean stream)
Create a new socket.
|
(package private) static boolean |
isThreadInterrupted()
Provides a simple mean for the JNI code to find out whether the
current thread was interrupted by a call to Thread.interrupt().
|
private static boolean |
lock(int fd,
long pos,
long len,
boolean shared,
boolean wait) |
boolean |
lock(long pos,
long len,
boolean shared,
boolean wait) |
MappedByteBuffer |
map(char mode,
long position,
int size) |
private static MappedByteBuffer |
map(int fd,
char mode,
long position,
int size) |
private static int |
max(int[] values) |
private static int |
open(String path,
int mode) |
void |
openFile(String path,
int mode) |
long |
position() |
private static long |
position(int fd) |
int |
read() |
private int |
read(byte[] dst,
int pos,
int len)
Reads a byte array directly.
|
int |
read(ByteBuffer dst)
Reads a byte buffer directly using the supplied file descriptor.
|
private int |
read(ByteBuffer dst,
int pos,
int len) |
private static int |
read(int fd) |
private static int |
read(int fd,
byte[] dst,
int position,
int len)
Use JikesRVM's internal read function - the fast way.
|
private static int |
read(int fd,
ByteBuffer dst)
Classpath's native read method.
|
long |
readScattering(ByteBuffer[] dsts,
int offset,
int length)
Reads into byte buffers directly using the supplied file descriptor.
|
private static long |
readScattering(int fd,
ByteBuffer[] dsts,
int offset,
int length) |
SocketAddress |
receive(ByteBuffer dst) |
private static int |
receive(int fd,
ByteBuffer dst,
ByteBuffer address) |
private static void |
seek(int fd,
long pos) |
void |
seek(long pos) |
int |
send(ByteBuffer src,
InetSocketAddress dst) |
private static int |
send(int fd,
ByteBuffer src,
byte[] addr,
int port) |
private static int |
send6(int fd,
ByteBuffer src,
byte[] addr,
int port) |
void |
setBlocking(boolean blocking) |
private static void |
setBlocking(int fd,
boolean blocking) |
long |
size() |
private static long |
size(int fd) |
private static int |
socket(boolean stream)
Create a new socket, returning the native file descriptor.
|
private static int |
stderr_fd() |
private static int |
stdin_fd() |
private static int |
stdout_fd() |
private static void |
truncate(int fd,
long len) |
void |
truncate(long length) |
private static void |
unlock(int fd,
long pos,
long len) |
void |
unlock(long pos,
long len) |
int |
write(byte[] src,
int pos,
int len)
Writes from a byte array using the supplied file descriptor.
|
int |
write(ByteBuffer src) |
int |
write(ByteBuffer src,
int pos,
int len) |
void |
write(int b) |
private static int |
write(int fd,
byte[] src,
int pos,
int len)
Use JikesRVM's internal read function - the fast way.
|
private static int |
write(int fd,
ByteBuffer src)
Classpath's native write method.
|
private static void |
write(int fd,
int b) |
long |
writeGathering(ByteBuffer[] srcs,
int offset,
int length) |
private long |
writeGathering(int fd,
ByteBuffer[] srcs,
int offset,
int length) |
private final VMChannel.State nfd
private VMChannel.Kind kind
private static int MAX_STANDARD_FD
private static final VMChannel.LocalByteArray localByteArray
public VMChannel()
VMChannel(int native_fd) throws IOException
IOException
public VMChannel.State getState()
private static int max(int[] values)
public static VMChannel getStdin() throws IOException
IOException
public static VMChannel getStdout() throws IOException
IOException
public static VMChannel getStderr() throws IOException
IOException
private static int stdin_fd()
private static int stdout_fd()
private static int stderr_fd()
public void setBlocking(boolean blocking) throws IOException
IOException
private static void setBlocking(int fd, boolean blocking) throws IOException
IOException
public int available() throws IOException
IOException
private static int available(int native_fd) throws IOException
IOException
public int read(ByteBuffer dst) throws IOException
dst
- Direct Byte Buffer to read to.IOException
- If an error occurs or dst is not a direct buffers.private int read(ByteBuffer dst, int pos, int len) throws IOException
IOException
private int read(byte[] dst, int pos, int len) throws IOException
dst
- Byte array to read topos
- Starting offset in the bufferlen
- Number of bytes to readIOException
- If an error occurs or dst is not a direct buffers.private static int read(int fd, byte[] dst, int position, int len) throws IOException
fd
- File descriptordst
- Destination bufferposition
- Starting offset in the bufferlen
- Number of bytes to readIOException
- when an error occurs during readingprivate static int read(int fd, ByteBuffer dst) throws IOException
fd
- the file descriptor of the file to readdst
- the buffer that the read bytes will be written toIOException
- when an error occurs during readingpublic int read() throws IOException
IOException
private static int read(int fd) throws IOException
IOException
public long readScattering(ByteBuffer[] dsts, int offset, int length) throws IOException
dsts
- An array direct byte buffers.offset
- Index of the first buffer to read to.length
- The number of buffers to read to.IOException
- If an error occurs or the dsts are not direct buffers.private static long readScattering(int fd, ByteBuffer[] dsts, int offset, int length) throws IOException
IOException
public SocketAddress receive(ByteBuffer dst) throws IOException
IOException
private static int receive(int fd, ByteBuffer dst, ByteBuffer address) throws IOException
IOException
public int write(byte[] src, int pos, int len) throws IOException
src
- The source buffer.pos
- Starting offset in the bufferlen
- Number of bytes to writeIOException
- when an error occurs during writingpublic int write(ByteBuffer src, int pos, int len) throws IOException
IOException
public int write(ByteBuffer src) throws IOException
IOException
private static int write(int fd, byte[] src, int pos, int len) throws IOException
fd
- File descriptorsrc
- Source bufferpos
- Starting offset in the bufferlen
- Number of bytes to writeIOException
- when an error occurs during writingprivate static int write(int fd, ByteBuffer src) throws IOException
fd
- the file's descriptorsrc
- the source buffer for the bytes that will be writtenIOException
- when an error occurs during writingpublic long writeGathering(ByteBuffer[] srcs, int offset, int length) throws IOException
IOException
private long writeGathering(int fd, ByteBuffer[] srcs, int offset, int length) throws IOException
IOException
public int send(ByteBuffer src, InetSocketAddress dst) throws IOException
IOException
private static int send(int fd, ByteBuffer src, byte[] addr, int port) throws IOException
IOException
private static int send6(int fd, ByteBuffer src, byte[] addr, int port) throws IOException
IOException
public void write(int b) throws IOException
IOException
private static void write(int fd, int b) throws IOException
IOException
private static void initIDs()
public void initSocket(boolean stream) throws IOException
stream
- Whether or not to create a streaming socket, or a datagram
socket.IOException
- If creating a new socket fails, or if this
channel already has its native descriptor initialized.private static int socket(boolean stream) throws IOException
stream
- Set to true for streaming sockets; false for datagrams.IOException
- If creating the socket fails.public boolean connect(InetSocketAddress saddr, int timeout) throws SocketException
saddr
- The address to connect to.timeout
- The connect timeout to use for blocking connects.SocketException
- If an error occurs while connecting.private static boolean connect(int fd, byte[] addr, int port, int timeout) throws SocketException
SocketException
private static boolean connect6(int fd, byte[] addr, int port, int timeout) throws SocketException
SocketException
public void disconnect() throws IOException
IOException
- If disconnecting this channel fails, or if this
channel is not a datagram channel.private static void disconnect(int fd) throws IOException
IOException
public InetSocketAddress getLocalAddress() throws IOException
IOException
private static int getsockname(int fd, ByteBuffer name) throws IOException
IOException
public InetSocketAddress getPeerAddress() throws IOException
IOException
private static int getpeername(int fd, ByteBuffer name) throws IOException
IOException
public VMChannel accept() throws IOException
IOException
- If an IO error occurs.private static int accept(int native_fd) throws IOException
IOException
public void openFile(String path, int mode) throws IOException
IOException
private static int open(String path, int mode) throws IOException
IOException
public long position() throws IOException
IOException
private static long position(int fd) throws IOException
IOException
public void seek(long pos) throws IOException
IOException
private static void seek(int fd, long pos) throws IOException
IOException
public void truncate(long length) throws IOException
IOException
private static void truncate(int fd, long len) throws IOException
IOException
public boolean lock(long pos, long len, boolean shared, boolean wait) throws IOException
IOException
private static boolean lock(int fd, long pos, long len, boolean shared, boolean wait) throws IOException
IOException
public void unlock(long pos, long len) throws IOException
IOException
private static void unlock(int fd, long pos, long len) throws IOException
IOException
public long size() throws IOException
IOException
private static long size(int fd) throws IOException
IOException
public MappedByteBuffer map(char mode, long position, int size) throws IOException
IOException
private static MappedByteBuffer map(int fd, char mode, long position, int size) throws IOException
IOException
public boolean flush(boolean metadata) throws IOException
IOException
private static boolean flush(int fd, boolean metadata) throws IOException
IOException
public void close() throws IOException
IOException
- If closing the socket fails, or if this object has
no open socket.static void close(int native_fd) throws IOException
IOException
static boolean isThreadInterrupted()
Provides a simple mean for the JNI code to find out whether the current thread was interrupted by a call to Thread.interrupt().