summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Koch <konqueror@gmx.de>2002-12-21 11:42:36 +0000
committerMichael Koch <konqueror@gmx.de>2002-12-21 11:42:36 +0000
commitab1b9b95b4e37ad2ca45e29529bf9f05c97ea54a (patch)
tree7cfe430cf5aaebf017e840ea71ec961c69b1db92
parentea69411498101135b89e17ff163d9e485b3c99c3 (diff)
downloadclasspath-ab1b9b95b4e37ad2ca45e29529bf9f05c97ea54a.tar.gz
2002-12-21 Michael Koch <konqueror@gmx.de>
* java/net/HttpURLConnection.java (HTTP_NOT_IMPLEMENTED): Must be public. * java/net/ServerSocket.java (closed): New member variable. (bind): Throw exception if socket is closed. (close): Set new member variable, close associated channel too. (isClosed): New method. * java/net/Socket.java (closed): New member variable. (bind): Throw exception if socket is closed. (connect): Throw exception if socket is closed. (close): Set new member variable, close associated channel too. (isClosed): New method. * java/nio/channels/DatagramChannel.java (connect): Added throws IOException. (disconnect): Added throws IOException. (read): Added throws IOException. (write): Added throws IOException. (receive): Added throws IOException. * java/nio/channels/Pipe.java (open): Added throws IOException. * java/nio/channels/SelectableChannel.java (configureBlocking): Added throws IOException. * java/nio/channels/SelectionKey.java (OP_ACCEPT): Fix constant value. (OP_CONNECT): Fix constant value. (OP_READ): Fix constant value. (OP_WRITE): Fix constant value. * java/nio/channels/ServerSocketChannel.java (accept): Added throws IOException. * java/nio/channels/SocketChannel.java (SocketChannel): Fixed implements. (read): Added throws IOException. (write): Added throws IOException. (finishConnect): Added throws IOException. * java/nio/channels/spi/AbstractInterruptibleChannel.java (end): Added throws AsynchronousCloseException. * java/nio/channels/spi/AbstractSelectableChannel.java (configureBlocking): Added throws IOException. (implCloseChannel): Added throws IOException. (implCloseSelectableChannel): Added throws IOException. (implConfigureBlocking): Added throws IOException. * java/nio/channels/spi/SelectorProvider.java (openDatagramChannel): Added throws IOException. (openPipe): Added throws IOException. (openSelector): Added throws IOException. (openServerSocketChannel): Added throws IOException. (openSocketChannel): Added throws IOException. (provider): Merge with libgcj.
-rw-r--r--ChangeLog52
-rw-r--r--java/net/HttpURLConnection.java2
-rw-r--r--java/net/ServerSocket.java25
-rw-r--r--java/net/Socket.java24
-rw-r--r--java/nio/channels/DatagramChannel.java21
-rw-r--r--java/nio/channels/Pipe.java3
-rw-r--r--java/nio/channels/SelectableChannel.java4
-rw-r--r--java/nio/channels/SelectionKey.java8
-rw-r--r--java/nio/channels/ServerSocketChannel.java2
-rw-r--r--java/nio/channels/SocketChannel.java17
-rw-r--r--java/nio/channels/spi/AbstractInterruptibleChannel.java2
-rw-r--r--java/nio/channels/spi/AbstractSelectableChannel.java8
-rw-r--r--java/nio/channels/spi/SelectorProvider.java15
13 files changed, 148 insertions, 35 deletions
diff --git a/ChangeLog b/ChangeLog
index ccd4c9ed4..caddbac81 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,55 @@
+2002-12-21 Michael Koch <konqueror@gmx.de>
+
+ * java/net/HttpURLConnection.java
+ (HTTP_NOT_IMPLEMENTED): Must be public.
+ * java/net/ServerSocket.java
+ (closed): New member variable.
+ (bind): Throw exception if socket is closed.
+ (close): Set new member variable, close associated channel too.
+ (isClosed): New method.
+ * java/net/Socket.java
+ (closed): New member variable.
+ (bind): Throw exception if socket is closed.
+ (connect): Throw exception if socket is closed.
+ (close): Set new member variable, close associated channel too.
+ (isClosed): New method.
+ * java/nio/channels/DatagramChannel.java
+ (connect): Added throws IOException.
+ (disconnect): Added throws IOException.
+ (read): Added throws IOException.
+ (write): Added throws IOException.
+ (receive): Added throws IOException.
+ * java/nio/channels/Pipe.java
+ (open): Added throws IOException.
+ * java/nio/channels/SelectableChannel.java
+ (configureBlocking): Added throws IOException.
+ * java/nio/channels/SelectionKey.java
+ (OP_ACCEPT): Fix constant value.
+ (OP_CONNECT): Fix constant value.
+ (OP_READ): Fix constant value.
+ (OP_WRITE): Fix constant value.
+ * java/nio/channels/ServerSocketChannel.java
+ (accept): Added throws IOException.
+ * java/nio/channels/SocketChannel.java
+ (SocketChannel): Fixed implements.
+ (read): Added throws IOException.
+ (write): Added throws IOException.
+ (finishConnect): Added throws IOException.
+ * java/nio/channels/spi/AbstractInterruptibleChannel.java
+ (end): Added throws AsynchronousCloseException.
+ * java/nio/channels/spi/AbstractSelectableChannel.java
+ (configureBlocking): Added throws IOException.
+ (implCloseChannel): Added throws IOException.
+ (implCloseSelectableChannel): Added throws IOException.
+ (implConfigureBlocking): Added throws IOException.
+ * java/nio/channels/spi/SelectorProvider.java
+ (openDatagramChannel): Added throws IOException.
+ (openPipe): Added throws IOException.
+ (openSelector): Added throws IOException.
+ (openServerSocketChannel): Added throws IOException.
+ (openSocketChannel): Added throws IOException.
+ (provider): Merge with libgcj.
+
2002-12-20 C. Brian Jones <cbj@gnu.org>
* BUGS: updated Savannah URL
diff --git a/java/net/HttpURLConnection.java b/java/net/HttpURLConnection.java
index 72221db47..ebc0f8175 100644
--- a/java/net/HttpURLConnection.java
+++ b/java/net/HttpURLConnection.java
@@ -255,7 +255,7 @@ public abstract class HttpURLConnection extends URLConnection
* The server does not support the requested functionality.
* @since 1.3
*/
- static final int HTTP_NOT_IMPLEMENTED = 501;
+ public static final int HTTP_NOT_IMPLEMENTED = 501;
/**
* The proxy encountered a bad response from the server it was proxy-ing for
diff --git a/java/net/ServerSocket.java b/java/net/ServerSocket.java
index 406a278e5..0285c128c 100644
--- a/java/net/ServerSocket.java
+++ b/java/net/ServerSocket.java
@@ -77,6 +77,8 @@ public class ServerSocket
*/
private ServerSocketChannel ch;
+ private boolean closed = false;
+
/**
* Constructor that simply sets the implementation.
*
@@ -200,6 +202,9 @@ public class ServerSocket
*/
public void bind (SocketAddress endpoint, int backlog) throws IOException
{
+ if (closed)
+ throw new SocketException ("ServerSocket is closed");
+
if (impl == null)
throw new IOException ("Cannot initialize Socket implementation");
@@ -315,7 +320,13 @@ public class ServerSocket
*/
public void close () throws IOException
{
- impl.close();
+ if (impl != null)
+ impl.close ();
+
+ if (ch != null)
+ ch.close ();
+
+ closed = true;
}
/**
@@ -345,13 +356,23 @@ public class ServerSocket
}
catch (SocketException e)
{
- return false;
+ return false;
}
return true;
}
/**
+ * Returns true if the socket is closed, otherwise false
+ *
+ * @since 1.4
+ */
+ public boolean isClosed()
+ {
+ return closed;
+ }
+
+ /**
* Sets the value of SO_TIMEOUT. A value of 0 implies that SO_TIMEOUT is
* disabled (ie, operations never time out). This is the number of
* milliseconds a socket operation can block before an
diff --git a/java/net/Socket.java b/java/net/Socket.java
index 09835d695..e57c1ed53 100644
--- a/java/net/Socket.java
+++ b/java/net/Socket.java
@@ -85,6 +85,8 @@ public class Socket
SocketChannel ch; // this field must have been set if created by SocketChannel
+ private boolean closed = false;
+
// Constructors
/**
@@ -308,6 +310,9 @@ public class Socket
*/
public void bind (SocketAddress bindpoint) throws IOException
{
+ if (closed)
+ throw new SocketException ("Socket is closed");
+
if ( !(bindpoint instanceof InetSocketAddress))
throw new IllegalArgumentException ();
@@ -330,6 +335,9 @@ public class Socket
public void connect (SocketAddress endpoint)
throws IOException
{
+ if (closed)
+ throw new SocketException ("Socket is closed");
+
if (! (endpoint instanceof InetSocketAddress))
throw new IllegalArgumentException ("Address type not supported");
@@ -357,6 +365,9 @@ public class Socket
public void connect (SocketAddress endpoint, int timeout)
throws IOException
{
+ if (closed)
+ throw new SocketException ("Socket is closed");
+
if (! (endpoint instanceof InetSocketAddress))
throw new IllegalArgumentException ("Address type not supported");
@@ -853,6 +864,11 @@ public class Socket
{
if (impl != null)
impl.close();
+
+ if (ch != null)
+ ch.close();
+
+ closed = true;
}
/**
@@ -1031,6 +1047,14 @@ public class Socket
}
/**
+ * Checks if the socket is closed.
+ */
+ public boolean isClosed ()
+ {
+ return closed;
+ }
+
+ /**
* Checks if the socket's input stream is shutdown
*/
public boolean isInputShutdown ()
diff --git a/java/nio/channels/DatagramChannel.java b/java/nio/channels/DatagramChannel.java
index 6c457557b..69877f09a 100644
--- a/java/nio/channels/DatagramChannel.java
+++ b/java/nio/channels/DatagramChannel.java
@@ -88,7 +88,7 @@ public abstract class DatagramChannel
* @exception IOException If an error occurs
* @exception NotYetConnectedException The channel's socket is not connected.
*/
- public final long write (ByteBuffer[] srcs)
+ public final long write (ByteBuffer[] srcs) throws IOException
{
long b = 0;
@@ -111,14 +111,15 @@ public abstract class DatagramChannel
* @exception SecurityException If a security manager has been installed and
* it does not permit datagrams to be sent to the given address.
*/
- public abstract DatagramChannel connect (SocketAddress remote);
+ public abstract DatagramChannel connect (SocketAddress remote)
+ throws IOException;
/**
* Disonnects this channel's socket.
*
* @exception IOException If an error occurs
*/
- public abstract DatagramChannel disconnect ();
+ public abstract DatagramChannel disconnect () throws IOException;
/**
* Tells whether or not this channel's socket is connected.
@@ -131,7 +132,7 @@ public abstract class DatagramChannel
/**
* Reads data from this channel.
*/
- public abstract int read (ByteBuffer dst);
+ public abstract int read (ByteBuffer dst) throws IOException;
/**
* Reads data from this channel.
@@ -139,7 +140,8 @@ public abstract class DatagramChannel
* @exception IOException If an error occurs.
* @exception NotYetConnectedException The channel's socket is not connected.
*/
- public abstract long read (ByteBuffer[] dsts, int offset, int length);
+ public abstract long read (ByteBuffer[] dsts, int offset, int length)
+ throws IOException;
/**
* Receives a datagram via this channel.
@@ -154,7 +156,7 @@ public abstract class DatagramChannel
* @exception SecurityException If a security manager has been installed and
* it does not permit datagrams to be sent to the given address.
*/
- public abstract SocketAddress receive (ByteBuffer dst);
+ public abstract SocketAddress receive (ByteBuffer dst) throws IOException;
/**
* Sends a datagram via this channel.
@@ -169,7 +171,7 @@ public abstract class DatagramChannel
* @exception SecurityException If a security manager has been installed and
* it does not permit datagrams to be sent to the given address.
*/
- public abstract int send (ByteBuffer src, SocketAddress target);
+ public abstract int send (ByteBuffer src, SocketAddress target) throws IOException;
/**
* Retrieves the channel's socket.
@@ -182,7 +184,7 @@ public abstract class DatagramChannel
* @exception IOException If an error occurs.
* @exception NotYetConnectedException The channel's socket is not connected.
*/
- public abstract int write (ByteBuffer src);
+ public abstract int write (ByteBuffer src) throws IOException;
/**
* Writes data to this channel.
@@ -190,7 +192,8 @@ public abstract class DatagramChannel
* @exception IOException If an error occurs.
* @exception NotYetConnectedException The channel's socket is not connected.
*/
- public abstract long write (ByteBuffer[] srcs, int offset, int length);
+ public abstract long write (ByteBuffer[] srcs, int offset, int length)
+ throws IOException;
/**
* Retrieves the valid operations for this channel.
diff --git a/java/nio/channels/Pipe.java b/java/nio/channels/Pipe.java
index 22f3d156f..939d7b52a 100644
--- a/java/nio/channels/Pipe.java
+++ b/java/nio/channels/Pipe.java
@@ -37,6 +37,7 @@ exception statement from your version. */
package java.nio.channels;
+import java.io.IOException;
import java.nio.channels.spi.AbstractSelectableChannel;
import java.nio.channels.spi.SelectorProvider;
@@ -104,7 +105,7 @@ public abstract class Pipe
*
* @exception IOException If an error occurs
*/
- public static Pipe open()
+ public static Pipe open() throws IOException
{
return SelectorProvider.provider ().openPipe();
}
diff --git a/java/nio/channels/SelectableChannel.java b/java/nio/channels/SelectableChannel.java
index 2bc5cc47e..72abac896 100644
--- a/java/nio/channels/SelectableChannel.java
+++ b/java/nio/channels/SelectableChannel.java
@@ -37,6 +37,7 @@ exception statement from your version. */
package java.nio.channels;
+import java.io.IOException;
import java.nio.channels.spi.AbstractInterruptibleChannel;
import java.nio.channels.spi.SelectorProvider;
@@ -67,7 +68,8 @@ public abstract class SelectableChannel
* is registered with one or more selectors.
* @exception IOException If an error occurs.
*/
- public abstract SelectableChannel configureBlocking (boolean block);
+ public abstract SelectableChannel configureBlocking (boolean block)
+ throws IOException;
/**
* Tells whether this channel is blocking or not.
diff --git a/java/nio/channels/SelectionKey.java b/java/nio/channels/SelectionKey.java
index 8d06a3011..39b66f190 100644
--- a/java/nio/channels/SelectionKey.java
+++ b/java/nio/channels/SelectionKey.java
@@ -43,10 +43,10 @@ package java.nio.channels;
*/
public abstract class SelectionKey
{
- public static final int OP_ACCEPT = 1<<0;
- public static final int OP_CONNECT = 1<<1;
- public static final int OP_READ = 1<<2;
- public static final int OP_WRITE = 1<<3;
+ public static final int OP_ACCEPT = 16;
+ public static final int OP_CONNECT = 8;
+ public static final int OP_READ = 1;
+ public static final int OP_WRITE = 4;
Object attached;
diff --git a/java/nio/channels/ServerSocketChannel.java b/java/nio/channels/ServerSocketChannel.java
index 16a3a82df..e41af2126 100644
--- a/java/nio/channels/ServerSocketChannel.java
+++ b/java/nio/channels/ServerSocketChannel.java
@@ -73,7 +73,7 @@ public abstract class ServerSocketChannel
* @exception SecurityException If a security manager has been installed and
* it does not permit access to the remote endpoint of the new connection.
*/
- public abstract SocketChannel accept ();
+ public abstract SocketChannel accept () throws IOException;
/**
* Retrieves the channels socket.
diff --git a/java/nio/channels/SocketChannel.java b/java/nio/channels/SocketChannel.java
index 368a8ee46..c22eb1d19 100644
--- a/java/nio/channels/SocketChannel.java
+++ b/java/nio/channels/SocketChannel.java
@@ -49,6 +49,7 @@ import java.net.SocketAddress;
* @since 1.4
*/
abstract public class SocketChannel extends AbstractSelectableChannel
+ implements ByteChannel, ScatteringByteChannel, GatheringByteChannel
{
/**
* Initializes this socket.
@@ -100,7 +101,7 @@ abstract public class SocketChannel extends AbstractSelectableChannel
* @exception IOException If an error occurs
* @exception NotYetConnectedException If this channel is not yet connected.
*/
- public final long read (ByteBuffer[] dsts)
+ public final long read (ByteBuffer[] dsts) throws IOException
{
long b = 0;
@@ -118,7 +119,7 @@ abstract public class SocketChannel extends AbstractSelectableChannel
* @exception IOException If an error occurs
* @exception NotYetConnectedException If this channel is not yet connected.
*/
- public final long write (ByteBuffer[] dsts)
+ public final long write (ByteBuffer[] dsts) throws IOException
{
long b = 0;
@@ -144,7 +145,7 @@ abstract public class SocketChannel extends AbstractSelectableChannel
* @exception IOException If an error occurs
* @exception NotYetConnectedException If this channel is not yet connected.
*/
- public abstract int read (ByteBuffer dst);
+ public abstract int read (ByteBuffer dst) throws IOException;
/**
* Connects the channel's socket to the remote address.
@@ -179,7 +180,7 @@ abstract public class SocketChannel extends AbstractSelectableChannel
* @exception NoConnectionPendingException If this channel is not connected
* and a connection operation has not been initiated.
*/
- public abstract boolean finishConnect ();
+ public abstract boolean finishConnect () throws IOException;
/**
* Tells whether or not the channel's socket is connected.
@@ -197,7 +198,8 @@ abstract public class SocketChannel extends AbstractSelectableChannel
* @exception IOException If an error occurs
* @exception NotYetConnectedException If this channel is not yet connected.
*/
- public abstract long read (ByteBuffer[] dsts, int offset, int length);
+ public abstract long read (ByteBuffer[] dsts, int offset, int length)
+ throws IOException;
/**
* Retrieves the channel's socket.
@@ -210,7 +212,7 @@ abstract public class SocketChannel extends AbstractSelectableChannel
* @exception IOException If an error occurs
* @exception NotYetConnectedException If this channel is not yet connected.
*/
- public abstract int write (ByteBuffer src);
+ public abstract int write (ByteBuffer src) throws IOException;
/**
* Writes data to the channel.
@@ -218,5 +220,6 @@ abstract public class SocketChannel extends AbstractSelectableChannel
* @exception IOException If an error occurs
* @exception NotYetConnectedException If this channel is not yet connected.
*/
- public abstract long write (ByteBuffer[] srcs, int offset, int length);
+ public abstract long write (ByteBuffer[] srcs, int offset, int length)
+ throws IOException;
}
diff --git a/java/nio/channels/spi/AbstractInterruptibleChannel.java b/java/nio/channels/spi/AbstractInterruptibleChannel.java
index 855087b5f..dd4177a8a 100644
--- a/java/nio/channels/spi/AbstractInterruptibleChannel.java
+++ b/java/nio/channels/spi/AbstractInterruptibleChannel.java
@@ -38,6 +38,7 @@ exception statement from your version. */
package java.nio.channels.spi;
import java.io.IOException;
+import java.nio.channels.AsynchronousCloseException;
import java.nio.channels.Channel;
import java.nio.channels.InterruptibleChannel;
@@ -84,6 +85,7 @@ public abstract class AbstractInterruptibleChannel
* I/O operation was interrupted.
*/
protected final void end (boolean completed)
+ throws AsynchronousCloseException
{
}
diff --git a/java/nio/channels/spi/AbstractSelectableChannel.java b/java/nio/channels/spi/AbstractSelectableChannel.java
index da03693d2..b13bb4af2 100644
--- a/java/nio/channels/spi/AbstractSelectableChannel.java
+++ b/java/nio/channels/spi/AbstractSelectableChannel.java
@@ -75,6 +75,7 @@ public abstract class AbstractSelectableChannel extends SelectableChannel
* Adjusts this channel's blocking mode.
*/
public final SelectableChannel configureBlocking (boolean block)
+ throws IOException
{
synchronized (LOCK)
{
@@ -90,7 +91,7 @@ public abstract class AbstractSelectableChannel extends SelectableChannel
*
* @exception IOException If an error occurs
*/
- protected final void implCloseChannel ()
+ protected final void implCloseChannel () throws IOException
{
implCloseSelectableChannel ();
}
@@ -98,12 +99,13 @@ public abstract class AbstractSelectableChannel extends SelectableChannel
/**
* Closes this selectable channel.
*/
- protected abstract void implCloseSelectableChannel ();
+ protected abstract void implCloseSelectableChannel () throws IOException;
/**
* Adjusts this channel's blocking mode.
*/
- protected abstract void implConfigureBlocking (boolean block);
+ protected abstract void implConfigureBlocking (boolean block)
+ throws IOException;
/**
* Tells whether or not every I/O operation on this channel will block
diff --git a/java/nio/channels/spi/SelectorProvider.java b/java/nio/channels/spi/SelectorProvider.java
index 82c328743..5ead8d5a5 100644
--- a/java/nio/channels/spi/SelectorProvider.java
+++ b/java/nio/channels/spi/SelectorProvider.java
@@ -38,6 +38,7 @@ exception statement from your version. */
package java.nio.channels.spi;
import gnu.java.nio.SelectorProviderImpl;
+import java.io.IOException;
import java.nio.channels.DatagramChannel;
import java.nio.channels.Pipe;
import java.nio.channels.ServerSocketChannel;
@@ -67,27 +68,27 @@ public abstract class SelectorProvider
/**
* Opens a datagram channel.
*/
- public abstract DatagramChannel openDatagramChannel ();
+ public abstract DatagramChannel openDatagramChannel () throws IOException;
/**
* Opens a pipe.
*/
- public abstract Pipe openPipe ();
+ public abstract Pipe openPipe () throws IOException;
/**
* Opens a selector.
*/
- public abstract AbstractSelector openSelector ();
+ public abstract AbstractSelector openSelector () throws IOException;
/**
* Opens a server socket channel.
*/
- public abstract ServerSocketChannel openServerSocketChannel ();
+ public abstract ServerSocketChannel openServerSocketChannel () throws IOException;
/**
* Opens a socket channel.
*/
- public abstract SocketChannel openSocketChannel ();
+ public abstract SocketChannel openSocketChannel () throws IOException;
/**
* Returns the system-wide default selector provider for this invocation
@@ -96,7 +97,9 @@ public abstract class SelectorProvider
public static SelectorProvider provider ()
{
if (pr == null)
- pr = new SelectorProviderImpl ();
+ {
+ pr = new SelectorProviderImpl ();
+ }
return pr;
}