From 2d0bb7d9c0cfacf3f6f0374232c8990600672d4f Mon Sep 17 00:00:00 2001 From: Antoine Levy-Lambert Date: Wed, 10 Sep 2003 18:20:46 +0000 Subject: [PATCH] close the socket created by the socket condition I have tested the issue. With the new code, within approximatively 100 milliseconds, the socket is gone while ant keeps running. PR: 23040 Submitted by: John C. Kendall (jkendall at technologist dot com) git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@275217 13f79535-47bb-0310-9956-ffa450edef68 --- WHATSNEW | 3 +++ .../apache/tools/ant/taskdefs/condition/Socket.java | 13 ++++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/WHATSNEW b/WHATSNEW index 245bc460f..e300a3d2d 100644 --- a/WHATSNEW +++ b/WHATSNEW @@ -236,6 +236,9 @@ Fixed bugs: * Project.toBoolean(String) now handles null as argument and does not throw a NullPointerException any more. +* The socket condition will now close the socket created to test. + Bugzilla Report 23040. + Other changes: -------------- * All tasks can be used outside of s. Note that some tasks diff --git a/src/main/org/apache/tools/ant/taskdefs/condition/Socket.java b/src/main/org/apache/tools/ant/taskdefs/condition/Socket.java index 432ebb71f..bde08b8b2 100644 --- a/src/main/org/apache/tools/ant/taskdefs/condition/Socket.java +++ b/src/main/org/apache/tools/ant/taskdefs/condition/Socket.java @@ -103,11 +103,22 @@ public class Socket extends ProjectComponent implements Condition { } log("Checking for listener at " + server + ":" + port, Project.MSG_VERBOSE); + java.net.Socket s = null; try { - new java.net.Socket(server, port); + s = new java.net.Socket(server, port); } catch (IOException e) { return false; } + finally { + if (s != null){ + try { + s.close(); + } + catch (IOException ioe){ + // Intentionally left blank + } + } + } return true; }