Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/ikvm-fork.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjfrijters <jfrijters>2011-07-15 13:05:26 +0400
committerjfrijters <jfrijters>2011-07-15 13:05:26 +0400
commit20464c682cbc4ab4b937774b1872928179870d74 (patch)
tree0df9c343c8ac6cb93ac55eec6e836a06e414b267 /openjdk/sun/nio/ch/IOUtil.java
parentafeabe4188bd04bcfc74b141664c294fc57c4b0a (diff)
Updated bulk of java.nio to OpenJDK 7.
Diffstat (limited to 'openjdk/sun/nio/ch/IOUtil.java')
-rw-r--r--openjdk/sun/nio/ch/IOUtil.java134
1 files changed, 133 insertions, 1 deletions
diff --git a/openjdk/sun/nio/ch/IOUtil.java b/openjdk/sun/nio/ch/IOUtil.java
index 9d26d6ef..eb413d4e 100644
--- a/openjdk/sun/nio/ch/IOUtil.java
+++ b/openjdk/sun/nio/ch/IOUtil.java
@@ -31,6 +31,7 @@ import java.net.*;
import java.nio.ByteBuffer;
import java.nio.channels.*;
import java.nio.channels.spi.*;
+import cli.System.Net.Sockets.SocketFlags;
/**
@@ -58,7 +59,138 @@ class IOUtil {
static void configureBlocking(FileDescriptor fd, boolean blocking) throws IOException
{
- Net.configureBlocking(fd, blocking);
+ fd.setSocketBlocking(blocking);
}
+ // this is a dummy method to allow us to use unmodified socket channel impls
+ static int fdVal(FileDescriptor fd)
+ {
+ return 0xbadc0de;
+ }
+
+ static int read(FileDescriptor fd, ByteBuffer dst, long position,
+ NativeDispatcher nd, Object lock)
+ throws IOException
+ {
+ if (dst.isReadOnly())
+ throw new IllegalArgumentException("Read-only buffer");
+ if (position != -1)
+ throw new ikvm.internal.NotYetImplementedError();
+
+ if (dst.hasArray())
+ {
+ byte[] buf = dst.array();
+ int len = readImpl(fd, buf, dst.arrayOffset() + dst.position(), dst.remaining());
+ if (len > 0)
+ {
+ dst.position(dst.position() + len);
+ }
+ return len;
+ }
+ else
+ {
+ byte[] buf = new byte[dst.remaining()];
+ int len = readImpl(fd, buf, 0, buf.length);
+ if (len > 0)
+ {
+ dst.put(buf, 0, len);
+ }
+ return len;
+ }
+ }
+
+ private static int readImpl(FileDescriptor fd, byte[] buf, int offset, int length) throws IOException
+ {
+ if (length == 0)
+ {
+ return 0;
+ }
+ try
+ {
+ if (false) throw new cli.System.Net.Sockets.SocketException();
+ if (false) throw new cli.System.ObjectDisposedException("");
+ int read = fd.getSocket().Receive(buf, offset, length, SocketFlags.wrap(SocketFlags.None));
+ return read == 0 ? IOStatus.EOF : read;
+ }
+ catch (cli.System.Net.Sockets.SocketException x)
+ {
+ if (x.get_ErrorCode() == SocketUtil.WSAESHUTDOWN)
+ {
+ // the socket was shutdown, so we have to return EOF
+ return IOStatus.EOF;
+ }
+ else if (x.get_ErrorCode() == SocketUtil.WSAEWOULDBLOCK)
+ {
+ // nothing to read and would block
+ return IOStatus.UNAVAILABLE;
+ }
+ throw SocketUtil.convertSocketExceptionToIOException(x);
+ }
+ catch (cli.System.ObjectDisposedException x1)
+ {
+ throw new SocketException("Socket is closed");
+ }
+ }
+
+ static native long read(FileDescriptor fd, ByteBuffer[] bufs, int offset, int length, NativeDispatcher nd)
+ throws IOException;
+
+ static int write(FileDescriptor fd, ByteBuffer src, long position,
+ NativeDispatcher nd, Object lock)
+ throws IOException
+ {
+ if (src.hasArray())
+ {
+ byte[] buf = src.array();
+ int len = writeImpl(fd, buf, src.arrayOffset() + src.position(), src.remaining());
+ if (len > 0)
+ {
+ src.position(src.position() + len);
+ }
+ return len;
+ }
+ else
+ {
+ int pos = src.position();
+ byte[] buf = new byte[src.remaining()];
+ src.get(buf);
+ int len = writeImpl(fd, buf, 0, buf.length);
+ if (len > 0)
+ {
+ src.position(pos + len);
+ }
+ return len;
+ }
+ }
+
+ private static int writeImpl(FileDescriptor fd, byte[] buf, int offset, int length) throws IOException
+ {
+ try
+ {
+ if (false) throw new cli.System.Net.Sockets.SocketException();
+ if (false) throw new cli.System.ObjectDisposedException("");
+ return fd.getSocket().Send(buf, offset, length, SocketFlags.wrap(SocketFlags.None));
+ }
+ catch (cli.System.Net.Sockets.SocketException x)
+ {
+ if (x.get_ErrorCode() == SocketUtil.WSAEWOULDBLOCK)
+ {
+ return IOStatus.UNAVAILABLE;
+ }
+ throw SocketUtil.convertSocketExceptionToIOException(x);
+ }
+ catch (cli.System.ObjectDisposedException x1)
+ {
+ throw new SocketException("Socket is closed");
+ }
+ }
+
+ static long write(FileDescriptor fd, ByteBuffer[] bufs, NativeDispatcher nd)
+ throws IOException
+ {
+ return write(fd, bufs, 0, bufs.length, nd);
+ }
+
+ static native long write(FileDescriptor fd, ByteBuffer[] bufs, int offset, int length, NativeDispatcher nd)
+ throws IOException;
}