summaryrefslogtreecommitdiff
path: root/libjava/gnu/java
diff options
context:
space:
mode:
Diffstat (limited to 'libjava/gnu/java')
-rw-r--r--libjava/gnu/java/nio/DatagramChannelImpl.java57
-rw-r--r--libjava/gnu/java/nio/SocketChannelImpl.java2
2 files changed, 49 insertions, 10 deletions
diff --git a/libjava/gnu/java/nio/DatagramChannelImpl.java b/libjava/gnu/java/nio/DatagramChannelImpl.java
index 3531803900a..baeac19deb6 100644
--- a/libjava/gnu/java/nio/DatagramChannelImpl.java
+++ b/libjava/gnu/java/nio/DatagramChannelImpl.java
@@ -57,6 +57,33 @@ public final class DatagramChannelImpl extends DatagramChannel
{
private NIODatagramSocket socket;
+ /**
+ * Indicates whether this channel initiated whatever operation
+ * is being invoked on our datagram socket.
+ */
+ private boolean inChannelOperation;
+
+ /**
+ * Indicates whether our datagram socket should ignore whether
+ * we are set to non-blocking mode. Certain operations on our
+ * socket throw an <code>IllegalBlockingModeException</code> if
+ * we are in non-blocking mode, <i>except</i> if the operation
+ * is initiated by us.
+ */
+ public final boolean isInChannelOperation()
+ {
+ return inChannelOperation;
+ }
+
+ /**
+ * Sets our indicator of whether we are initiating an I/O operation
+ * on our socket.
+ */
+ public final void setInChannelOperation(boolean b)
+ {
+ inChannelOperation = b;
+ }
+
protected DatagramChannelImpl (SelectorProvider provider)
throws IOException
{
@@ -178,7 +205,7 @@ public final class DatagramChannelImpl extends DatagramChannel
try
{
DatagramPacket packet;
- int len = dst.remaining();
+ int len = dst.capacity() - dst.position();
if (dst.hasArray())
{
@@ -196,23 +223,23 @@ public final class DatagramChannelImpl extends DatagramChannel
try
{
begin();
+ setInChannelOperation(true);
socket.receive (packet);
completed = true;
}
finally
{
end (completed);
+ setInChannelOperation(false);
}
if (!dst.hasArray())
{
dst.put (packet.getData(), packet.getOffset(), packet.getLength());
}
-
- // FIMXE: remove this testing code.
- for (int i = 0; i < packet.getLength(); i++)
+ else
{
- System.out.println ("Byte " + i + " has value " + packet.getData() [packet.getOffset() + i]);
+ dst.position (dst.position() + packet.getLength());
}
return packet.getSocketAddress();
@@ -246,13 +273,25 @@ public final class DatagramChannelImpl extends DatagramChannel
DatagramPacket packet = new DatagramPacket (buffer, offset, len, target);
- // FIMXE: remove this testing code.
- for (int i = 0; i < packet.getLength(); i++)
+ boolean completed = false;
+ try
+ {
+ begin();
+ setInChannelOperation(true);
+ socket.send(packet);
+ completed = true;
+ }
+ finally
+ {
+ end (completed);
+ setInChannelOperation(false);
+ }
+
+ if (src.hasArray())
{
- System.out.println ("Byte " + i + " has value " + packet.getData() [packet.getOffset() + i]);
+ src.position (src.position() + len);
}
- socket.send (packet);
return len;
}
}
diff --git a/libjava/gnu/java/nio/SocketChannelImpl.java b/libjava/gnu/java/nio/SocketChannelImpl.java
index 4df40b481a6..d490529f873 100644
--- a/libjava/gnu/java/nio/SocketChannelImpl.java
+++ b/libjava/gnu/java/nio/SocketChannelImpl.java
@@ -226,7 +226,7 @@ public final class SocketChannelImpl extends SocketChannel
int offset = 0;
InputStream input = socket.getInputStream();
int available = input.available();
- int len = dst.remaining();
+ int len = dst.capacity() - dst.position();
if (available == 0)
return 0;