>>>>> Matthew Levine writes:
Matthew> I've been using the after command to implement packet retries
Matthew> and I noticed that when the after callback executes, I lose
Matthew> my context in the for loop its in.
Matthew> A little code might help....
Matthew> foreach host $hosts { set msgid [send_packet $host] set
Matthew> rx($msgid) [after $timeout [list send_packet $host]] }
Matthew> On the receive side I cancel the after command when I receive
Matthew> an ack for the packet I send.
Matthew> The problem is, if that after callback ever gets executed, I
Matthew> lose my place in the for loop and send_packet isn't called
Matthew> for the rest of the $hosts.
No, this can't be true. Tcl never executes an after callback while
evaluating a for loop. I did the following script based on your
example and it produces the output "a b c d a b c d " as it should.
set hosts [list a b c d]
set timeout 1000
proc send_packet {host} {
puts -nonewline "$host "
flush stdout
}
foreach host $hosts {
set msgid [send_packet $host]
set rx($msgid) [after $timeout [list send_packet $host]]
}
Matthew> I've tried to replace the after code with the job command
Matthew> from Scotty but get the same result.
Matthew> Is there a reason why this happens and how I can workaround
Matthew> it?
I guess your problem is somewhere else.
/js
-- Juergen Schoenwaelder Technical University Braunschweig <schoenw@ibr.cs.tu-bs.de> Dept. Operating Systems & Computer Networks Phone: +49 531 391 3289 Bueltenweg 74/75, 38106 Braunschweig, Germany Fax: +49 531 391 5936 <URL:http://www.ibr.cs.tu-bs.de/~schoenw/>-- !! This message is brought to you via the `tkined & scotty' mailing list. !! Please do not reply to this message to unsubscribe. To subscribe or !! unsubscribe, send a mail message to <tkined-request@ibr.cs.tu-bs.de>. !! See http://wwwsnmp.cs.utwente.nl/~schoenw/scotty/ for more information.
This archive was generated by hypermail 2b29 : Mon Jan 08 2001 - 15:27:56 MET