aboutsummaryrefslogtreecommitdiff
path: root/libjava
diff options
context:
space:
mode:
authormkoch <mkoch@138bc75d-0d04-0410-961f-82ee72b054a4>2004-02-03 14:50:59 +0000
committermkoch <mkoch@138bc75d-0d04-0410-961f-82ee72b054a4>2004-02-03 14:50:59 +0000
commitd1c9d75809ef965116f3572234db6ace08859a03 (patch)
tree6de78ce207d490d81134407b56798e02e134f144 /libjava
parentd10e6ec6a4dc3f307c064ed56d3c526625f3451a (diff)
2004-02-03 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. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/branches/gcc-3_4-branch@77172 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libjava')
-rw-r--r--libjava/ChangeLog26
-rw-r--r--libjava/gnu/java/net/PlainSocketImpl.java27
-rw-r--r--libjava/gnu/java/nio/ServerSocketChannelImpl.java6
-rw-r--r--libjava/gnu/java/nio/SocketChannelImpl.java55
-rw-r--r--libjava/java/net/ServerSocket.java9
-rw-r--r--libjava/java/net/Socket.java7
-rw-r--r--libjava/java/nio/channels/spi/AbstractSelectableChannel.java7
7 files changed, 118 insertions, 19 deletions
diff --git a/libjava/ChangeLog b/libjava/ChangeLog
index 5ad848c551c..d84d571fd82 100644
--- a/libjava/ChangeLog
+++ b/libjava/ChangeLog
@@ -1,3 +1,29 @@
+2004-02-03 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.
+
2004-01-24 Michael Koch <konqueror@gmx.de>
* gnu/java/net/protocol/http/Connection.java
diff --git a/libjava/gnu/java/net/PlainSocketImpl.java b/libjava/gnu/java/net/PlainSocketImpl.java
index 80139115cfe..08267838b8a 100644
--- a/libjava/gnu/java/net/PlainSocketImpl.java
+++ b/libjava/gnu/java/net/PlainSocketImpl.java
@@ -120,6 +120,33 @@ public final class PlainSocketImpl extends SocketImpl
private OutputStream out;
/**
+ * Indicates whether a channel initiated whatever operation
+ * is being invoked on this socket.
+ */
+ private boolean inChannelOperation;
+
+ /**
+ * Indicates whether we should ignore whether any associated
+ * channel is set to non-blocking mode. Certain operations
+ * throw an <code>IllegalBlockingModeException</code> if the
+ * associated channel is in non-blocking mode, <i>except</i>
+ * if the operation is invoked by the channel itself.
+ */
+ public final boolean isInChannelOperation()
+ {
+ return inChannelOperation;
+ }
+
+ /**
+ * Sets our indicator of whether an I/O operation is being
+ * initiated by a channel.
+ */
+ public final void setInChannelOperation(boolean b)
+ {
+ inChannelOperation = b;
+ }
+
+ /**
* Default do nothing constructor
*/
public PlainSocketImpl()
diff --git a/libjava/gnu/java/nio/ServerSocketChannelImpl.java b/libjava/gnu/java/nio/ServerSocketChannelImpl.java
index fd975d20a7a..e26d23699ad 100644
--- a/libjava/gnu/java/nio/ServerSocketChannelImpl.java
+++ b/libjava/gnu/java/nio/ServerSocketChannelImpl.java
@@ -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/libjava/gnu/java/nio/SocketChannelImpl.java b/libjava/gnu/java/nio/SocketChannelImpl.java
index efb5fec481b..3f0ca78f949 100644
--- a/libjava/gnu/java/nio/SocketChannelImpl.java
+++ b/libjava/gnu/java/nio/SocketChannelImpl.java
@@ -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);
}
}
@@ -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())
{
diff --git a/libjava/java/net/ServerSocket.java b/libjava/java/net/ServerSocket.java
index 9a2d82d9c76..c660aada966 100644
--- a/libjava/java/net/ServerSocket.java
+++ b/libjava/java/net/ServerSocket.java
@@ -345,9 +345,14 @@ public class ServerSocket
if (isClosed())
throw new SocketException("ServerSocket is closed");
+ // The Sun spec says that if we have an associated channel and
+ // it is in non-blocking mode, we throw an IllegalBlockingModeException.
+ // However, in our implementation if the channel itself initiated this
+ // operation, then we must honor it regardless of its blocking mode.
if (getChannel() != null
- && !getChannel().isBlocking())
- throw new IllegalBlockingModeException();
+ && !getChannel().isBlocking ()
+ && !((PlainSocketImpl) getImpl()).isInChannelOperation())
+ throw new IllegalBlockingModeException ();
impl.accept(socket.getImpl());
}
diff --git a/libjava/java/net/Socket.java b/libjava/java/net/Socket.java
index 9322e929ec3..7d325060813 100644
--- a/libjava/java/net/Socket.java
+++ b/libjava/java/net/Socket.java
@@ -420,8 +420,13 @@ public class Socket
if (! (endpoint instanceof InetSocketAddress))
throw new IllegalArgumentException("unsupported address type");
+ // The Sun spec says that if we have an associated channel and
+ // it is in non-blocking mode, we throw an IllegalBlockingModeException.
+ // However, in our implementation if the channel itself initiated this
+ // operation, then we must honor it regardless of its blocking mode.
if (getChannel() != null
- && !getChannel().isBlocking ())
+ && !getChannel().isBlocking ()
+ && !((PlainSocketImpl) getImpl()).isInChannelOperation())
throw new IllegalBlockingModeException ();
if (!isBound ())
diff --git a/libjava/java/nio/channels/spi/AbstractSelectableChannel.java b/libjava/java/nio/channels/spi/AbstractSelectableChannel.java
index 17d6a2eaea1..c0a654f0748 100644
--- a/libjava/java/nio/channels/spi/AbstractSelectableChannel.java
+++ b/libjava/java/nio/channels/spi/AbstractSelectableChannel.java
@@ -80,8 +80,11 @@ public abstract class AbstractSelectableChannel extends SelectableChannel
{
synchronized (blockingLock())
{
- implConfigureBlocking(blocking);
- this.blocking = blocking;
+ if (this.blocking != blocking)
+ {
+ implConfigureBlocking(blocking);
+ this.blocking = blocking;
+ }
}
return this;