Test suite - user server socket to optimize port detection
Optimized port detection for tcl, use 'socket -server' instead of 'socket' to rule out port on TIME_WAIT
@@ -443,15 +443,17 @@ proc find_available_port {start count} {
if {$port < $start || $port >= $start+$count} {
set port $start
}
- if {[catch {set fd1 [socket 127.0.0.1 $port]}] &&
- [catch {set fd2 [socket 127.0.0.1 [expr $port+10000]]}]} {
- set ::last_port_attempted $port
- return $port
+ set fd1 -1
+ if {[catch {set fd1 [socket -server 127.0.0.1 $port]}] ||
+ [catch {set fd2 [socket -server 127.0.0.1 [expr $port+10000]]}]} {
+ if {$fd1 != -1} {
+ close $fd1
+ }
} else {
- catch {
close $fd1
close $fd2
- }
+ set ::last_port_attempted $port
+ return $port
}
incr port
}
