From 8124b5fb585273485814508c23908f35f44d3fba Mon Sep 17 00:00:00 2001
From: dgp <dgp@users.sourceforge.net>
Date: Thu, 3 May 2012 20:22:35 +0000
Subject: 3428754 Test socket-14.2 tolerate [socket -async] connection that
 connects synchronously.

---
 ChangeLog         |  3 +++
 tests/socket.test | 21 ++++++++++++---------
 2 files changed, 15 insertions(+), 9 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index fd02eff..06cd5d5 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,8 @@
 2012-05-03  Don Porter  <dgp@users.sourceforge.net>
 
+	* tests/socket.test:	[Bug 3428754] Test socket-14.2 tolerate
+	[socket -async] connection that connects synchronously.
+
 	* unix/tclUnixSock.c:	[Bug 3428753] Fix [socket -async] connections
 	that manage to connect synchronously.
 
diff --git a/tests/socket.test b/tests/socket.test
index f63f5ca..f06a548 100644
--- a/tests/socket.test
+++ b/tests/socket.test
@@ -1776,17 +1776,20 @@ test socket-14.1 {[socket -async] fileevent while still connecting} \
 test socket-14.2 {[socket -async] fileevent connection refused} \
     -constraints [list socket supported_any] \
     -body {
-        set client [socket -async localhost [randport]]
-        fileevent $client writable {set x [fconfigure $client -error]}
-        set after [after 1000 {set x timeout}]
-        vwait x
-        if {$x eq "timeout"} {
-            append x ": [fconfigure $client -error]"
-        }
+        if {[catch {socket -async localhost [randport]} client]} {
+	    regexp {[^:]*: (.*)} $client -> x
+	} else {
+            fileevent $client writable {set x [fconfigure $client -error]}
+            set after [after 1000 {set x timeout}]
+            vwait x
+	    after cancel $after
+            if {$x eq "timeout"} {
+                append x ": [fconfigure $client -error]"
+            }
+	    close $client
+	}
         set x
     } -cleanup {
-        after cancel $after
-        close $client
         unset x
     } -result "connection refused"
 test socket-14.3 {[socket -async] when server only listens on IPv6} \
-- 
cgit v0.12

