aboutsummaryrefslogtreecommitdiff
path: root/libjava/java/net/ServerSocket.java
diff options
context:
space:
mode:
authorBryce McKinlay <bryce@mckinlay.net.nz>2003-08-07 06:30:16 +0000
committerBryce McKinlay <bryce@gcc.gnu.org>2003-08-07 07:30:16 +0100
commit62ad7de1e049583a413e9bfe7fbbbf02ab2b1aea (patch)
treeac19591df1828db5dd120609de724f7fb980f668 /libjava/java/net/ServerSocket.java
parentfdc49e10e69a5f250b6784c77c3617fb853e5634 (diff)
downloadgcc-62ad7de1e049583a413e9bfe7fbbbf02ab2b1aea.zip
gcc-62ad7de1e049583a413e9bfe7fbbbf02ab2b1aea.tar.gz
gcc-62ad7de1e049583a413e9bfe7fbbbf02ab2b1aea.tar.bz2
re PR libgcj/10868 (java.net.ServerSocket's constructors create and leak extra sockets)
* java/net/Socket.java (Socket (SocketImpl)): Don't allow null SocketImpl. Update Javadoc. (bind): Call close() not impl.close() in event of exception. (connect): Likewise. Remove superfluous null checks throughout. * java/net/ServerSocket.java (ServerSocket (int, int, InetAddress)): Don't create an extra socket. Fix for PR libgcj/10868. (bind): Clean up exception handling. Remove superfluous null checks throughout. From-SVN: r70219
Diffstat (limited to 'libjava/java/net/ServerSocket.java')
-rw-r--r--libjava/java/net/ServerSocket.java55
1 files changed, 5 insertions, 50 deletions
diff --git a/libjava/java/net/ServerSocket.java b/libjava/java/net/ServerSocket.java
index 699319e..3614354 100644
--- a/libjava/java/net/ServerSocket.java
+++ b/libjava/java/net/ServerSocket.java
@@ -154,12 +154,6 @@ public class ServerSocket
{
this();
- if (impl == null)
- throw new IOException("Cannot initialize Socket implementation");
-
- // create socket
- impl.create(true);
-
// bind/listen socket
bind (new InetSocketAddress (bindAddr, port), backlog);
}
@@ -208,9 +202,6 @@ public class ServerSocket
if (closed)
throw new SocketException ("ServerSocket is closed");
- if (impl == null)
- throw new IOException ("Cannot initialize Socket implementation");
-
if (! (endpoint instanceof InetSocketAddress))
throw new IllegalArgumentException ("Address type not supported");
@@ -220,45 +211,24 @@ public class ServerSocket
if (s != null)
s.checkListen (tmp.getPort ());
- // bind to address/port
try
{
- impl.bind (tmp.getAddress (), tmp.getPort ());
+ impl.bind (tmp.getAddress (), tmp.getPort ());
+ impl.listen(backlog);
}
catch (IOException exception)
{
- impl.close();
+ close();
throw exception;
}
catch (RuntimeException exception)
{
- impl.close();
+ close();
throw exception;
}
catch (Error error)
{
- impl.close();
- throw error;
- }
-
- // listen on socket
- try
- {
- impl.listen(backlog);
- }
- catch (IOException exception)
- {
- impl.close();
- throw exception;
- }
- catch (RuntimeException exception)
- {
- impl.close();
- throw exception;
- }
- catch (Error error)
- {
- impl.close();
+ close();
throw error;
}
}
@@ -320,9 +290,6 @@ public class ServerSocket
*/
public Socket accept () throws IOException
{
- if (impl == null)
- throw new IOException ("Cannot initialize Socket implementation");
-
SecurityManager sm = System.getSecurityManager ();
if (sm != null)
sm.checkListen (impl.getLocalPort ());
@@ -466,9 +433,6 @@ public class ServerSocket
public void setReuseAddress (boolean on)
throws SocketException
{
- if (impl == null)
- throw new SocketException ("Cannot initialize Socket implementation");
-
impl.setOption (SocketOptions.SO_REUSEADDR, new Boolean (on));
}
@@ -482,9 +446,6 @@ public class ServerSocket
public boolean getReuseAddress()
throws SocketException
{
- if (impl == null)
- throw new SocketException ("Cannot initialize Socket implementation");
-
Object reuseaddr = impl.getOption (SocketOptions.SO_REUSEADDR);
if (!(reuseaddr instanceof Boolean))
@@ -508,9 +469,6 @@ public class ServerSocket
public void setReceiveBufferSize (int size)
throws SocketException
{
- if (impl == null)
- throw new SocketException ("Not connected");
-
if (size <= 0)
throw new IllegalArgumentException ("SO_RCVBUF value must be > 0");
@@ -531,9 +489,6 @@ public class ServerSocket
public int getReceiveBufferSize ()
throws SocketException
{
- if (impl == null)
- throw new SocketException ("Not connected");
-
Object buf = impl.getOption (SocketOptions.SO_RCVBUF);
if (!(buf instanceof Integer))