aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Koch <konqueror@gmx.de>2003-06-08 10:12:09 +0000
committerMichael Koch <mkoch@gcc.gnu.org>2003-06-08 10:12:09 +0000
commit742ed2f3daf7e24066154963409f867acf10e8a9 (patch)
tree076b1d41bea49b88e8f54b25b466cf2cef10072a
parentf61e2125825d5e69ddb10d2232af4ca0e94ecf26 (diff)
downloadgcc-742ed2f3daf7e24066154963409f867acf10e8a9.zip
gcc-742ed2f3daf7e24066154963409f867acf10e8a9.tar.gz
gcc-742ed2f3daf7e24066154963409f867acf10e8a9.tar.bz2
2003-06-08 Michael Koch <konqueror@gmx.de>
* java/net/Socket.java (Socket): Dont initialize inputShutdown and outputShutdown twice, call bind() and connect() to actually do the bind and connect tasks. (bind): Connect to canonical address if bindpoint is null, create socket and bind it to bindpoint. (connect): Check for exceptions. From-SVN: r67618
-rw-r--r--libjava/ChangeLog9
-rw-r--r--libjava/java/net/Socket.java120
2 files changed, 65 insertions, 64 deletions
diff --git a/libjava/ChangeLog b/libjava/ChangeLog
index 815a170..bdfd775 100644
--- a/libjava/ChangeLog
+++ b/libjava/ChangeLog
@@ -1,5 +1,14 @@
2003-06-08 Michael Koch <konqueror@gmx.de>
+ * java/net/Socket.java
+ (Socket): Dont initialize inputShutdown and outputShutdown twice,
+ call bind() and connect() to actually do the bind and connect tasks.
+ (bind): Connect to canonical address if bindpoint is null, create
+ socket and bind it to bindpoint.
+ (connect): Check for exceptions.
+
+2003-06-08 Michael Koch <konqueror@gmx.de>
+
* java/net/DatagramSocket.java
(DatagramSocket): No need to set SO_REUSEADDRESS here. This belongs
into the Multicast constructors.
diff --git a/libjava/java/net/Socket.java b/libjava/java/net/Socket.java
index cd3b5ec..8535fa9 100644
--- a/libjava/java/net/Socket.java
+++ b/libjava/java/net/Socket.java
@@ -281,8 +281,6 @@ public class Socket
boolean stream) throws IOException
{
this();
- this.inputShutdown = false;
- this.outputShutdown = false;
if (impl == null)
throw new IOException("Cannot initialize Socket implementation");
@@ -291,59 +289,13 @@ public class Socket
if (sm != null)
sm.checkConnect(raddr.getHostName(), rport);
- // create socket
- impl.create(stream);
+ // bind/connect socket
+ bind (new InetSocketAddress (laddr, lport));
+ connect (new InetSocketAddress (raddr, rport));
// FIXME: JCL p. 1586 says if localPort is unspecified, bind to any port,
// i.e. '0' and if localAddr is unspecified, use getLocalAddress() as
// that default. JDK 1.2 doc infers not to do a bind.
-
- // bind/connect to address/port
- if (laddr != null)
- {
- try
- {
- impl.bind(laddr, lport);
- }
- catch (IOException exception)
- {
- impl.close();
- throw exception;
- }
- catch (RuntimeException exception)
- {
- impl.close();
- throw exception;
- }
- catch (Error error)
- {
- impl.close();
- throw error;
- }
- }
-
- if (raddr != null)
- {
- try
- {
- impl.connect(raddr, rport);
- }
- catch (IOException exception)
- {
- impl.close();
- throw exception;
- }
- catch (RuntimeException exception)
- {
- impl.close();
- throw exception;
- }
- catch (Error error)
- {
- impl.close();
- throw error;
- }
- }
}
/**
@@ -362,12 +314,40 @@ public class Socket
{
if (closed)
throw new SocketException ("Socket is closed");
+
+ // XXX: JDK 1.4.1 API documentation says that if bindpoint is null the
+ // socket will be bound to an ephemeral port and a valid local address.
+ if (bindpoint == null)
+ bindpoint = new InetSocketAddress (InetAddress.ANY_IF, 0);
if ( !(bindpoint instanceof InetSocketAddress))
throw new IllegalArgumentException ();
InetSocketAddress tmp = (InetSocketAddress) bindpoint;
- impl.bind (tmp.getAddress(), tmp.getPort());
+
+ // create socket
+ impl.create (true);
+
+ // bind to address/port
+ try
+ {
+ impl.bind (tmp.getAddress(), tmp.getPort());
+ }
+ catch (IOException exception)
+ {
+ impl.close ();
+ throw exception;
+ }
+ catch (RuntimeException exception)
+ {
+ impl.close ();
+ throw exception;
+ }
+ catch (Error error)
+ {
+ impl.close ();
+ throw error;
+ }
}
/**
@@ -385,16 +365,7 @@ 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");
-
- if (ch != null && !ch.isBlocking ())
- throw new IllegalBlockingModeException ();
-
- impl.connect (endpoint, 0);
+ connect (endpoint, 0);
}
/**
@@ -423,8 +394,29 @@ public class Socket
if (ch != null && !ch.isBlocking ())
throw new IllegalBlockingModeException ();
-
- impl.connect (endpoint, timeout);
+
+ if (!isBound ())
+ bind (null);
+
+ try
+ {
+ impl.connect (endpoint, timeout);
+ }
+ catch (IOException exception)
+ {
+ impl.close ();
+ throw exception;
+ }
+ catch (RuntimeException exception)
+ {
+ impl.close ();
+ throw exception;
+ }
+ catch (Error error)
+ {
+ impl.close ();
+ throw error;
+ }
}
/**