This is the mail archive of the
java-patches@gcc.gnu.org
mailing list for the Java project.
Re: [PATCH]: DatagramChannel + Misc. Channel Fixes
- From: Mohan Embar <gnustuff at thisiscool dot com>
- To: Michael Koch <konqueror at gmx dot de>
- Cc: GCJ Patches <java-patches at gcc dot gnu dot org>
- Date: Sun, 01 Feb 2004 13:45:25 -0600
- Subject: Re: [PATCH]: DatagramChannel + Misc. Channel Fixes
- Reply-to: gnustuff at thisiscool dot com
Hi Michael,
>Can you recreate this as unified diff please ? Its much more readbale.
Here you go....
-- Mohan
http://www.thisiscool.com/
http://www.animalsong.org/
ChangeLog
2004-02-01 Mohan Embar <gnustuff@thisiscool.com>
* gnu/java/nio/DatagramChannelImpl.java
(inChannelOperation): New field.
(isInChannelOperation): New accessor.
(setInChannelOperation): New modifier.
(receive): Use capacity() - position() of destination
buffer instead of remaining(). Set and reset our "in
channel operation indicator" before and after delegating
the receive to our datagram socket. Removed testing code.
Update destination buffer's current position if it is
backed by a byte array (hasArray() is true).
(send): Set and reset our "in channel operation indicator"
before and after delegating the send to our datagram socket.
Removed testing code. Update source buffer's current position
if it is backed by a byte array (hasArray() is true).
* gnu/java/nio/SocketChannelImpl.java (read(ByteBuffer)):
Use capacity() - position() of destination buffer instead
of remaining().
* java/net/DatagramSocket.java (receive): Don't throw an
IllegalBlockingModeException if we have a non-blocking
channel which initiated this operation.
(send): Likewise.
Index: gnu/java/nio/DatagramChannelImpl.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/gnu/java/nio/DatagramChannelImpl.java,v
retrieving revision 1.8
diff -u -2 -r1.8 DatagramChannelImpl.java
--- gnu/java/nio/DatagramChannelImpl.java 7 Jan 2004 16:51:49 -0000 1.8
+++ gnu/java/nio/DatagramChannelImpl.java 1 Feb 2004 19:43:53 -0000
@@ -58,4 +58,31 @@
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
@@ -179,5 +206,5 @@
{
DatagramPacket packet;
- int len = dst.remaining();
+ int len = dst.capacity() - dst.position();
if (dst.hasArray())
@@ -197,4 +224,5 @@
{
begin();
+ setInChannelOperation(true);
socket.receive (packet);
completed = true;
@@ -203,4 +231,5 @@
{
end (completed);
+ setInChannelOperation(false);
}
@@ -209,9 +238,7 @@
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());
}
@@ -247,11 +274,23 @@
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;
}
Index: gnu/java/nio/SocketChannelImpl.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/gnu/java/nio/SocketChannelImpl.java,v
retrieving revision 1.16
diff -u -2 -r1.16 SocketChannelImpl.java
--- gnu/java/nio/SocketChannelImpl.java 30 Jan 2004 13:43:18 -0000 1.16
+++ gnu/java/nio/SocketChannelImpl.java 1 Feb 2004 19:43:53 -0000
@@ -227,5 +227,5 @@
InputStream input = socket.getInputStream();
int available = input.available();
- int len = dst.remaining();
+ int len = dst.capacity() - dst.position();
if (available == 0)
Index: java/net/DatagramSocket.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/net/DatagramSocket.java,v
retrieving revision 1.35
diff -u -2 -r1.35 DatagramSocket.java
--- java/net/DatagramSocket.java 9 Dec 2003 15:39:23 -0000 1.35
+++ java/net/DatagramSocket.java 1 Feb 2004 19:43:56 -0000
@@ -40,4 +40,5 @@
import gnu.java.net.PlainDatagramSocketImpl;
+import gnu.java.nio.DatagramChannelImpl;
import java.io.IOException;
import java.nio.channels.DatagramChannel;
@@ -566,5 +567,6 @@
if (getChannel() != null
- && !getChannel().isBlocking ())
+ && !getChannel().isBlocking ()
+ && !((DatagramChannelImpl) getChannel()).isInChannelOperation())
throw new IllegalBlockingModeException ();
@@ -619,5 +621,6 @@
if (getChannel() != null
- && !getChannel().isBlocking ())
+ && !getChannel().isBlocking ()
+ && !((DatagramChannelImpl) getChannel()).isInChannelOperation())
throw new IllegalBlockingModeException ();