Posted to tcl by Ro at Mon Mar 05 15:18:05 GMT 2007view raw

  1.  
  2.  
  3. console show
  4.  
  5. set dir [file dirname [info nameofexe]]
  6.  
  7. lappend auto_path [file join $dir lib]
  8.  
  9.  
  10. proc file_get {fn} {set f [open $fn r] ; set c [read $f] ; close $f ; return $c}
  11.  
  12. proc get_1000ip_list {} {
  13. return [split [file_get [file join $::dir 1000ip.txt]] \n]
  14. }
  15.  
  16.  
  17.  
  18. proc socketzoom {count IP s} {
  19.  
  20. fileevent $s writable {}
  21.  
  22.  
  23. set emsg [fconfigure $s -error]
  24.  
  25. close $s
  26.  
  27. if {![string equal $emsg ""]} {
  28. puts "$count : $IP ERROR $s : $emsg" ; update
  29. } else {
  30. puts "$count : $IP conn! $s" ; update
  31. }
  32.  
  33.  
  34. }
  35.  
  36.  
  37.  
  38. label .fired -font {{Lucida Console} 16}
  39. pack .fired -fill x -expand 1
  40.  
  41.  
  42. set count 0
  43. foreach IP [get_1000ip_list] {
  44.  
  45. set s [socket -async $IP 80]
  46. fileevent $s writable [list socketzoom $count $IP $s]
  47.  
  48. .fired conf -text "Fired Off $count"
  49.  
  50. update
  51. incr count
  52. }
  53.  
  54.  
  55.  

Comments

Posted by davygrvy at Mon Mar 05 19:08:43 GMT 2007 [text] [code]

remove the [update] calls from [socketzoom]. Calling update from a fileevent is bad and can eat-up your stack space. The event loop is already servicing this proc, so entering the event loop again increases the stack without unwinding.