summaryrefslogtreecommitdiffstats
path: root/tests/socket.test
diff options
context:
space:
mode:
authorjan.nijtmans <nijtmans@users.sourceforge.net>2017-04-12 09:23:23 (GMT)
committerjan.nijtmans <nijtmans@users.sourceforge.net>2017-04-12 09:23:23 (GMT)
commit948bd5e9965da403d358767ce982c65b3af971ae (patch)
tree9ec3570dae1bac7204826279ecb7a2007f7a8ffe /tests/socket.test
parent224849c744f0f6ceb853162afd318b858835850c (diff)
downloadtcl-948bd5e9965da403d358767ce982c65b3af971ae.zip
tcl-948bd5e9965da403d358767ce982c65b3af971ae.tar.gz
tcl-948bd5e9965da403d358767ce982c65b3af971ae.tar.bz2
Fix sporadically errors in zlib-8.x and socket tests, cherry-picked from "fix-1997007" branch. Credit to "sebres"!
Diffstat (limited to 'tests/socket.test')
-rw-r--r--tests/socket.test17
1 files changed, 16 insertions, 1 deletions
diff --git a/tests/socket.test b/tests/socket.test
index d43c41c..a3e5704 100644
--- a/tests/socket.test
+++ b/tests/socket.test
@@ -69,7 +69,22 @@ testConstraint exec [llength [info commands exec]]
# Produce a random port number in the Dynamic/Private range
# from 49152 through 65535.
-proc randport {} { expr {int(rand()*16383+49152)} }
+proc randport {} {
+ # firstly try dynamic port via server-socket(0):
+ set port 0x7fffffff
+ catch {
+ set port [lindex [fconfigure [set s [socket -server {} 0]] -sockname] 2]
+ close $s
+ }
+ while {[catch {
+ close [socket -server {} $port]
+ } msg]} {
+ if {[incr i] > 1000} {return -code error "too many iterations to get free random port: $msg"}
+ # try random port:
+ set port [expr {int(rand()*16383+49152)}]
+ }
+ return $port
+}
# Test the latency of tcp connections over the loopback interface. Some OSes
# (e.g. NetBSD) seem to use the Nagle algorithm and delayed ACKs, so it takes