summaryrefslogtreecommitdiff
path: root/gnu/java/nio
diff options
context:
space:
mode:
authorMichael Koch <konqueror@gmx.de>2004-02-06 09:13:23 +0000
committerMichael Koch <konqueror@gmx.de>2004-02-06 09:13:23 +0000
commit9c4f694033cff2a2c955ec9aa1bd7baf874fc06e (patch)
tree0bc0828df239ad3bf211635f564e7240804b9e5e /gnu/java/nio
parentc01c55fe280172bac8de0271571874fcd0b5d2c3 (diff)
downloadclasspath-9c4f694033cff2a2c955ec9aa1bd7baf874fc06e.tar.gz
2004-02-06 Michael Koch <konqueror@gmx.de>
* gnu/java/nio/NIOServerSocket.java (impl): Unused, removed. * gnu/java/nio/SocketChannelImpl.java (finnishConnect): Don't throw NoConnectionPendingException if not connected or no connection pending. 2004-02-06 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. 2004-02-06 Mohan Embar <gnustuff@thisiscool.com> * gnu/java/net/PlainSocketImpl.java (inChannelOperation): New field. (isInChannelOperation): New accessor. (setInChannelOperation): New modifier. * gnu/java/nio/ServerSocketChannelImpl.java (accept): Set and reset our server socket's PlainSocketImpl's "in channel operation" indicator before and after delegating the accept to our server socket. * gnu/java/nio/SocketChannelImpl.java (connect): Set and reset our socket's PlainSocketImpl's "in channel operation" indicator before and after delegating the operation to our socket. (read): Likewise. (write): Likewise. * java/net/ServerSocket.java (implAccept): Don't throw an IllegalBlockingModeException if we have a non-blocking channel which initiated this accept operation. * java/net/Socket.java (connect): Don't throw an IllegalBlockingModeException if we have a non-blocking channel which initiated this connect operation. * java/nio/channels/spi/AbstractSelectableChannel.java (configureBlocking): Only call implConfigureBlocking() if the desired blocking mode is different from our current one.
Diffstat (limited to 'gnu/java/nio')
-rw-r--r--gnu/java/nio/DatagramChannelImpl.java57
-rw-r--r--gnu/java/nio/NIOServerSocket.java3
-rw-r--r--gnu/java/nio/ServerSocketChannelImpl.java10
-rw-r--r--gnu/java/nio/SocketChannelImpl.java61
4 files changed, 101 insertions, 30 deletions
diff --git a/gnu/java/nio/DatagramChannelImpl.java b/gnu/java/nio/DatagramChannelImpl.java
index 353180390..baeac19de 100644
--- a/gnu/java/nio/DatagramChannelImpl.java
+++ b/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/gnu/java/nio/NIOServerSocket.java b/gnu/java/nio/NIOServerSocket.java
index 89def3bb5..316424776 100644
--- a/gnu/java/nio/NIOServerSocket.java
+++ b/gnu/java/nio/NIOServerSocket.java
@@ -1,5 +1,5 @@
/* NIOServerSocket.java --
- Copyright (C) 2003 Free Software Foundation, Inc.
+ Copyright (C) 2003, 2004 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -50,7 +50,6 @@ import java.nio.channels.SocketChannel;
*/
public final class NIOServerSocket extends ServerSocket
{
- private PlainSocketImpl impl;
private ServerSocketChannelImpl channel;
protected NIOServerSocket (ServerSocketChannelImpl channel)
diff --git a/gnu/java/nio/ServerSocketChannelImpl.java b/gnu/java/nio/ServerSocketChannelImpl.java
index fd975d20a..76e1ce324 100644
--- a/gnu/java/nio/ServerSocketChannelImpl.java
+++ b/gnu/java/nio/ServerSocketChannelImpl.java
@@ -1,5 +1,5 @@
/* ServerSocketChannelImpl.java --
- Copyright (C) 2002, 2003 Free Software Foundation, Inc.
+ Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -69,7 +69,7 @@ public final class ServerSocketChannelImpl extends ServerSocketChannel
{
return serverSocket.getPlainSocketImpl().getNativeFD();
}
-
+
public void finalizer()
{
if (connected)
@@ -107,6 +107,11 @@ public final class ServerSocketChannelImpl extends ServerSocketChannel
try
{
+ begin();
+ serverSocket.getPlainSocketImpl().setInChannelOperation(true);
+ // indicate that a channel is initiating the accept operation
+ // so that the socket ignores the fact that we might be in
+ // non-blocking mode.
NIOSocket socket = (NIOSocket) serverSocket.accept();
completed = true;
return socket.getChannel();
@@ -117,6 +122,7 @@ public final class ServerSocketChannelImpl extends ServerSocketChannel
}
finally
{
+ serverSocket.getPlainSocketImpl().setInChannelOperation(false);
end (completed);
}
}
diff --git a/gnu/java/nio/SocketChannelImpl.java b/gnu/java/nio/SocketChannelImpl.java
index efb5fec48..d4dd6e056 100644
--- a/gnu/java/nio/SocketChannelImpl.java
+++ b/gnu/java/nio/SocketChannelImpl.java
@@ -1,5 +1,5 @@
/* SocketChannelImpl.java --
- Copyright (C) 2002, 2003 Free Software Foundation, Inc.
+ Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -136,23 +136,35 @@ public final class SocketChannelImpl extends SocketChannel
if (((InetSocketAddress) remote).isUnresolved())
throw new UnresolvedAddressException();
- if (isBlocking())
- {
- // Do blocking connect.
- socket.connect (remote);
- return true;
- }
-
- // Do non-blocking connect.
try
{
- socket.connect (remote, NIOConstants.DEFAULT_TIMEOUT);
- return true;
+ socket.getPlainSocketImpl().setInChannelOperation(true);
+ // indicate that a channel is initiating the accept operation
+ // so that the socket ignores the fact that we might be in
+ // non-blocking mode.
+
+ if (isBlocking())
+ {
+ // Do blocking connect.
+ socket.connect (remote);
+ return true;
+ }
+
+ // Do non-blocking connect.
+ try
+ {
+ socket.connect (remote, NIOConstants.DEFAULT_TIMEOUT);
+ return true;
+ }
+ catch (SocketTimeoutException e)
+ {
+ connectionPending = true;
+ return false;
+ }
}
- catch (SocketTimeoutException e)
+ finally
{
- connectionPending = true;
- return false;
+ socket.getPlainSocketImpl().setInChannelOperation(false);
}
}
@@ -162,7 +174,7 @@ public final class SocketChannelImpl extends SocketChannel
if (!isOpen())
throw new ClosedChannelException();
- if (!connectionPending)
+ if (!isConnected() && !connectionPending)
throw new NoConnectionPendingException();
if (isConnected())
@@ -214,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;
@@ -238,12 +250,14 @@ public final class SocketChannelImpl extends SocketChannel
try
{
begin();
+ socket.getPlainSocketImpl().setInChannelOperation(true);
readBytes = input.read (data, offset, len);
completed = true;
}
finally
{
end (completed);
+ socket.getPlainSocketImpl().setInChannelOperation(false);
}
if (readBytes > 0)
@@ -301,7 +315,20 @@ public final class SocketChannelImpl extends SocketChannel
}
OutputStream output = socket.getOutputStream();
- output.write (data, offset, len);
+ boolean completed = false;
+
+ try
+ {
+ begin();
+ socket.getPlainSocketImpl().setInChannelOperation(true);
+ output.write (data, offset, len);
+ completed = true;
+ }
+ finally
+ {
+ end (completed);
+ socket.getPlainSocketImpl().setInChannelOperation(false);
+ }
if (src.hasArray())
{