summaryrefslogtreecommitdiffstats
path: root/tests/socket.test
diff options
context:
space:
mode:
authorjan.nijtmans <nijtmans@users.sourceforge.net>2017-04-12 09:35:18 (GMT)
committerjan.nijtmans <nijtmans@users.sourceforge.net>2017-04-12 09:35:18 (GMT)
commit473bfc0f18451046035f638732a609fc86d5a0aa (patch)
tree2d936efa3a46c26a2f9c39b73421666db8b0e5d9 /tests/socket.test
parent4775249efa107caa7895328913957997cf0bc6d8 (diff)
parent948bd5e9965da403d358767ce982c65b3af971ae (diff)
downloadtcl-473bfc0f18451046035f638732a609fc86d5a0aa.zip
tcl-473bfc0f18451046035f638732a609fc86d5a0aa.tar.gz
tcl-473bfc0f18451046035f638732a609fc86d5a0aa.tar.bz2
merge core-8-6-branch
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 9a09c0f..d3d56fa 100644
--- a/tests/socket.test
+++ b/tests/socket.test
@@ -74,7 +74,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
+}
# Check if testsocket testflags is available
testConstraint testsocket_testflags [expr {![catch {