summaryrefslogtreecommitdiff
path: root/java/net/Socket.java
diff options
context:
space:
mode:
authorTorsten Rupp <rupp@aicas.com>2003-04-30 14:10:31 +0000
committerTorsten Rupp <rupp@aicas.com>2003-04-30 14:10:31 +0000
commit6b72f5d1ec065f5206470bd31be7ddc6742749d4 (patch)
tree7530bb6c44975de3943a5d34b6e3a2196eb572c7 /java/net/Socket.java
parent6466694184b2821555277780eaf2ba7758cd42ed (diff)
downloadclasspath-6b72f5d1ec065f5206470bd31be7ddc6742749d4.tar.gz
Added try-catch-blocks to
* Socket.java: socket() * ServerSocket.java: socket() * DatagramSocket.java: socket() with clean-up of file-descriptors in case bind(), connect() or listen() fail. This fix will avoid loss of file-descriptors in the case create() is executed successfully, but bind/connect/listen fail with an exception. Then close() was not called and the file-descriptor allcoated by create() was not returned to the OS.
Diffstat (limited to 'java/net/Socket.java')
-rw-r--r--java/net/Socket.java35
1 files changed, 30 insertions, 5 deletions
diff --git a/java/net/Socket.java b/java/net/Socket.java
index 7070838c7..d30cebc0c 100644
--- a/java/net/Socket.java
+++ b/java/net/Socket.java
@@ -291,16 +291,41 @@ public class Socket
if (sm != null)
sm.checkConnect(raddr.getHostName(), rport);
+ // create socket
impl.create(stream);
+ // bind/connect to address/port
// 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.
- if (laddr != null)
- impl.bind(laddr, lport);
-
- if (raddr != null)
- impl.connect(raddr, rport);
+ 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;
+ }
+ }
}
/**