diff options
Diffstat (limited to 'libjava/java/net/ServerSocket.java')
-rw-r--r-- | libjava/java/net/ServerSocket.java | 60 |
1 files changed, 49 insertions, 11 deletions
diff --git a/libjava/java/net/ServerSocket.java b/libjava/java/net/ServerSocket.java index b706acc..36f93e8 100644 --- a/libjava/java/net/ServerSocket.java +++ b/libjava/java/net/ServerSocket.java @@ -38,6 +38,7 @@ exception statement from your version. */ package java.net; import java.io.IOException; +import java.nio.channels.IllegalBlockingModeException; import java.nio.channels.ServerSocketChannel; /* Written using on-line Java Platform 1.2 API Specification. @@ -50,7 +51,7 @@ import java.nio.channels.ServerSocketChannel; * listens for and accepts connections. At that point the client and * server sockets are ready to communicate with one another utilizing * whatever application layer protocol they desire. - * <p> + * * As with the <code>Socket</code> class, most instance methods of this class * simply redirect their calls to an implementation class. * @@ -82,9 +83,13 @@ public class ServerSocket private ServerSocketChannel ch; /** - * Private constructor that simply sets the implementation. + * Constructor that simply sets the implementation. + * + * @exception IOException If an error occurs + * + * @specnote This constructor is public since JDK 1.4 */ - private ServerSocket() + public ServerSocket() throws IOException { if (factory != null) impl = factory.createSocketImpl(); @@ -100,9 +105,11 @@ public class ServerSocket * @param port The port number to bind to * * @exception IOException If an error occurs + * @exception SecurityException If a security manager exists and its + * checkListen method doesn't allow the operation */ public ServerSocket (int port) - throws java.io.IOException + throws IOException { this(port, 50); } @@ -117,9 +124,11 @@ public class ServerSocket * @param backlog The length of the pending connection queue * * @exception IOException If an error occurs + * @exception SecurityException If a security manager exists and its + * checkListen method doesn't allow the operation */ public ServerSocket (int port, int backlog) - throws java.io.IOException + throws IOException { this(port, backlog, null); } @@ -136,11 +145,13 @@ public class ServerSocket * @param bindAddr The address to bind to, or null to bind to all addresses * * @exception IOException If an error occurs + * @exception SecurityException If a security manager exists and its + * checkListen method doesn't allow the operation * * @since 1.1 */ public ServerSocket (int port, int backlog, InetAddress bindAddr) - throws java.io.IOException + throws IOException { this(); if (impl == null) @@ -164,6 +175,9 @@ public class ServerSocket * @param endpoint The socket address to bind to * * @exception IOException If an error occurs + * @exception IllegalArgumentException If address type is not supported + * @exception SecurityException If a security manager exists and its + * checkListen method doesn't allow the operation * * @since 1.4 */ @@ -173,6 +187,9 @@ public class ServerSocket if (impl == null) throw new IOException ("Cannot initialize Socket implementation"); + if (! (endpoint instanceof InetSocketAddress)) + throw new IllegalArgumentException ("Address type not supported"); + InetSocketAddress tmp = (InetSocketAddress) endpoint; SecurityManager s = System.getSecurityManager (); @@ -187,14 +204,22 @@ public class ServerSocket * * @param endpoint The socket address to bind to * @param backlog The length of the pending connection queue + * * @exception IOException If an error occurs + * @exception IllegalArgumentException If address type is not supported + * @exception SecurityException If a security manager exists and its + * checkListen method doesn't allow the operation + * + * @since 1.4 */ - public void bind (SocketAddress endpoint, int backlog) - throws java.io.IOException + public void bind (SocketAddress endpoint, int backlog) throws IOException { if (impl == null) throw new IOException ("Cannot initialize Socket implementation"); + if (! (endpoint instanceof InetSocketAddress)) + throw new IllegalArgumentException ("Address type not supported"); + InetSocketAddress tmp = (InetSocketAddress) endpoint; SecurityManager s = System.getSecurityManager (); @@ -253,8 +278,14 @@ public class ServerSocket * connection is available. * * @exception IOException If an error occurs + * @exception SecurityException If a security manager exists and its + * checkListen method doesn't allow the operation + * @exception IllegalBlockingModeException If this socket has an associated + * channel, and the channel is in non-blocking mode + * @exception SocketTimeoutException If a timeout was previously set with + * setSoTimeout and the timeout has been reached */ - public Socket accept () throws IOException + public Socket accept () throws IOException { Socket s = new Socket(); implAccept (s); @@ -270,11 +301,17 @@ public class ServerSocket * @param socket The socket that is used for the accepted connection * * @exception IOException If an error occurs + * @exception IllegalBlockingModeException If this socket has an associated + * channel, and the channel is in non-blocking mode * * @since 1.1 */ - protected final void implAccept (Socket s) throws IOException + protected final void implAccept (Socket s) + throws IOException { + if (ch != null && !ch.isBlocking()) + throw new IllegalBlockingModeException(); + impl.accept(s.impl); } @@ -329,7 +366,7 @@ public class ServerSocket * * @param timeout The new SO_TIMEOUT value * - * @exception IOException If an error occurs + * @exception SocketException If an error occurs * * @since 1.1 */ @@ -408,6 +445,7 @@ public class ServerSocket * @param size The new receive buffer size. * * @exception SocketException If an error occurs or Socket is not connected + * @exception IllegalArgumentException If size is 0 or negative * * @since 1.4 */ |