| 304 | # sorts fetch_urls in order of ping time |
| 305 | proc sortsites {args} { |
| 306 | global fetch_urls fallback_mirror_site |
| 307 | |
| 308 | set fallback_mirror_list [mirror_sites $fallback_mirror_site {} {}] |
| 309 | |
| 310 | foreach {url_var distfile} $fetch_urls { |
| 311 | global portfetch::$url_var |
| 312 | if {![info exists $url_var]} { |
| 313 | ui_error [format [msgcat::mc "No defined site for tag: %s, using master_sites"] $url_var] |
| 314 | set url_var master_sites |
| 315 | global portfetch::$url_var |
| 316 | } |
| 317 | set urllist [set $url_var] |
| 318 | set pinglist {} |
| 319 | |
| 320 | foreach site $urllist { |
| 321 | regexp {[a-zA-Z]+://([a-zA-Z0-9\.-]+)[(/?$)|(/.*)]} $site -> host |
| 322 | |
| 323 | set msecs 0 |
| 324 | foreach fallback $fallback_mirror_list { |
| 325 | if {[string match [append fallback *] $site]} { |
| 326 | set msecs 20000 |
| 327 | break |
| 328 | } |
| 329 | } |
| 330 | if {$msecs == 0} { |
| 331 | ui_debug "Pinging $host..." |
| 332 | if {[catch {exec ping -noq -c1 -t1 $host | grep round-trip | cut -d / -f 5} msecs]} { |
| 333 | set msecs 10000; # ping failed, so put it last in the list |
| 334 | } |
| 335 | } |
| 336 | lappend pinglist [ list $site $msecs ] |
| 337 | } |
| 338 | |
| 339 | set pinglist [ lsort -real -index 1 $pinglist ] |
| 340 | |
| 341 | set $url_var {} |
| 342 | foreach pair $pinglist { |
| 343 | lappend $url_var [lindex $pair 0] |
| 344 | } |
| 345 | } |
| 346 | } |
| 347 | |