* 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. From-SVN: r76956
This commit is contained in:
parent
d1615643e5
commit
7dcc98e25c
7 changed files with 127 additions and 26 deletions
|
@ -1,3 +1,29 @@
|
||||||
|
2004-01-30 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-29 Mohan Embar <gnustuff@thisiscool.com>
|
2004-01-29 Mohan Embar <gnustuff@thisiscool.com>
|
||||||
|
|
||||||
* java/io/BufferedReader.java (sbuf): New field.
|
* java/io/BufferedReader.java (sbuf): New field.
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/* PlainSocketImpl.java -- Default socket implementation
|
/* PlainSocketImpl.java -- Default socket implementation
|
||||||
Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003
|
Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004
|
||||||
Free Software Foundation, Inc.
|
Free Software Foundation, Inc.
|
||||||
|
|
||||||
This file is part of GNU Classpath.
|
This file is part of GNU Classpath.
|
||||||
|
@ -119,6 +119,33 @@ public final class PlainSocketImpl extends SocketImpl
|
||||||
*/
|
*/
|
||||||
private OutputStream out;
|
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
|
* Default do nothing constructor
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/* ServerSocketChannelImpl.java --
|
/* 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.
|
This file is part of GNU Classpath.
|
||||||
|
|
||||||
|
@ -69,7 +69,7 @@ public final class ServerSocketChannelImpl extends ServerSocketChannel
|
||||||
{
|
{
|
||||||
return serverSocket.getPlainSocketImpl().getNativeFD();
|
return serverSocket.getPlainSocketImpl().getNativeFD();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void finalizer()
|
public void finalizer()
|
||||||
{
|
{
|
||||||
if (connected)
|
if (connected)
|
||||||
|
@ -107,6 +107,11 @@ public final class ServerSocketChannelImpl extends ServerSocketChannel
|
||||||
|
|
||||||
try
|
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();
|
NIOSocket socket = (NIOSocket) serverSocket.accept();
|
||||||
completed = true;
|
completed = true;
|
||||||
return socket.getChannel();
|
return socket.getChannel();
|
||||||
|
@ -117,6 +122,7 @@ public final class ServerSocketChannelImpl extends ServerSocketChannel
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
|
serverSocket.getPlainSocketImpl().setInChannelOperation(false);
|
||||||
end (completed);
|
end (completed);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/* SocketChannelImpl.java --
|
/* 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.
|
This file is part of GNU Classpath.
|
||||||
|
|
||||||
|
@ -136,23 +136,35 @@ public final class SocketChannelImpl extends SocketChannel
|
||||||
if (((InetSocketAddress) remote).isUnresolved())
|
if (((InetSocketAddress) remote).isUnresolved())
|
||||||
throw new UnresolvedAddressException();
|
throw new UnresolvedAddressException();
|
||||||
|
|
||||||
if (isBlocking())
|
|
||||||
{
|
|
||||||
// Do blocking connect.
|
|
||||||
socket.connect (remote);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Do non-blocking connect.
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
socket.connect (remote, NIOConstants.DEFAULT_TIMEOUT);
|
socket.getPlainSocketImpl().setInChannelOperation(true);
|
||||||
return 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;
|
socket.getPlainSocketImpl().setInChannelOperation(false);
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -238,12 +250,14 @@ public final class SocketChannelImpl extends SocketChannel
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
begin();
|
begin();
|
||||||
|
socket.getPlainSocketImpl().setInChannelOperation(true);
|
||||||
readBytes = input.read (data, offset, len);
|
readBytes = input.read (data, offset, len);
|
||||||
completed = true;
|
completed = true;
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
end (completed);
|
end (completed);
|
||||||
|
socket.getPlainSocketImpl().setInChannelOperation(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (readBytes > 0)
|
if (readBytes > 0)
|
||||||
|
@ -301,7 +315,20 @@ public final class SocketChannelImpl extends SocketChannel
|
||||||
}
|
}
|
||||||
|
|
||||||
OutputStream output = socket.getOutputStream();
|
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())
|
if (src.hasArray())
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
/* ServerSocket.java -- Class for implementing server side sockets
|
/* ServerSocket.java -- Class for implementing server side sockets
|
||||||
Copyright (C) 1998, 1999, 2000, 2002, 2003 Free Software Foundation, Inc.
|
Copyright (C) 1998, 1999, 2000, 2002, 2003, 2004
|
||||||
|
Free Software Foundation, Inc.
|
||||||
|
|
||||||
This file is part of GNU Classpath.
|
This file is part of GNU Classpath.
|
||||||
|
|
||||||
|
@ -345,9 +346,14 @@ public class ServerSocket
|
||||||
if (isClosed())
|
if (isClosed())
|
||||||
throw new SocketException("ServerSocket is closed");
|
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
|
if (getChannel() != null
|
||||||
&& !getChannel().isBlocking())
|
&& !getChannel().isBlocking ()
|
||||||
throw new IllegalBlockingModeException();
|
&& !((PlainSocketImpl) getImpl()).isInChannelOperation())
|
||||||
|
throw new IllegalBlockingModeException ();
|
||||||
|
|
||||||
impl.accept(socket.getImpl());
|
impl.accept(socket.getImpl());
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
/* Socket.java -- Client socket implementation
|
/* Socket.java -- Client socket implementation
|
||||||
Copyright (C) 1998, 1999, 2000, 2002, 2003 Free Software Foundation, Inc.
|
Copyright (C) 1998, 1999, 2000, 2002, 2003, 2004
|
||||||
|
Free Software Foundation, Inc.
|
||||||
|
|
||||||
This file is part of GNU Classpath.
|
This file is part of GNU Classpath.
|
||||||
|
|
||||||
|
@ -420,8 +421,13 @@ public class Socket
|
||||||
if (! (endpoint instanceof InetSocketAddress))
|
if (! (endpoint instanceof InetSocketAddress))
|
||||||
throw new IllegalArgumentException("unsupported address type");
|
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
|
if (getChannel() != null
|
||||||
&& !getChannel().isBlocking ())
|
&& !getChannel().isBlocking ()
|
||||||
|
&& !((PlainSocketImpl) getImpl()).isInChannelOperation())
|
||||||
throw new IllegalBlockingModeException ();
|
throw new IllegalBlockingModeException ();
|
||||||
|
|
||||||
if (!isBound ())
|
if (!isBound ())
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/* AbstractSelectableChannel.java
|
/* AbstractSelectableChannel.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.
|
This file is part of GNU Classpath.
|
||||||
|
|
||||||
|
@ -80,8 +80,11 @@ public abstract class AbstractSelectableChannel extends SelectableChannel
|
||||||
{
|
{
|
||||||
synchronized (blockingLock())
|
synchronized (blockingLock())
|
||||||
{
|
{
|
||||||
implConfigureBlocking(blocking);
|
if (this.blocking != blocking)
|
||||||
this.blocking = blocking;
|
{
|
||||||
|
implConfigureBlocking(blocking);
|
||||||
|
this.blocking = blocking;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue