Re: passing parameter by reference?



In article <1133224036.299815.300780@xxxxxxxxxxxxxxxxxxxxxxxxxxxx>,
slebetman@xxxxxxxxx <slebetman@xxxxxxxxx> wrote:
.
.
.
>Actually, yes to a point. Fileevents may not return a complete packet
>and another fileevent on a different socket may trigger. So your
>concerns are valid.
>
>As previous posters have replied, you can use upvar to sort of pass by
>reference.
>
>Personally, for my own web server, I used a global array variable. Just
>use the socket name for the index to the array. For example, you can
>have a global $timeout($channel) to keep track of timeouts and
>$buffer($channel) to buffer incoming data etc.. This way you don't have
>to worry about the second fileevent clobbering your global since each
>fileevent has its own place in the global array.
>

I regard "Fileevents may not return a complete packet and
another fileevent on a different socket may trigger" as
at least doubly confusing:

A. Fileevents are guaranteed to return
a complete packet, in a weak sense
(if the channel is line-delimited,
for example, any fileevent will end
in a newline, 'cept for eof ...);
B. Stock Tcl is singly-threaded, so
a fileevent can trigger only when
the programmer has given control to
the event loop.

I'm fairly sure you know these things, but I suspect naive
readers might misinterpret your description.

I entirely agree that a lot of us index interesting associative
arrays with $channel.
.



Relevant Pages

  • Re: Socket Infinitely Readable, Not EOF
    ... More (probably useless) information: I tried using the fact that the ... fileevent / readable proc fired and the length of data read from the ... socket is 0 to close the socket, ... Subsequent reconnects fail in the same manner perhaps half a dozen times ...
    (comp.lang.tcl)
  • Re: Not able to know the device is alive or not after rebooting...
    ... Puneet wrote: ... I mean we fire an event that listen continuosly that socket ... to listen--but fileevent only is useful after ... until you know that the host is up. ...
    (comp.lang.tcl)
  • Re: Socket Infinitely Readable, Not EOF
    ... tcl script opens two socket servers, ... an indicator of "connection reset by peer". ... zero-length fileevent should not occur in normal operation. ...
    (comp.lang.tcl)
  • async tls socket using too much cpu
    ... I'm having a problem using the tls package and asynchronous ... The problem is that too much CPU is consumed. ... The socket is opened using. ... Run step 3 when [fileevent] says the socket is ...
    (comp.lang.tcl)
  • Re: Socket Infinitely Readable, Not EOF
    ... non-blocking on the readable event appears to be the problem. ... I wouldn't say fileevent is strictly an alternate to non-blocking. ... I suppose what I could do is try setting the socket blocking, ... What I'm thinking may be going on here is issues at the TCP level. ...
    (comp.lang.tcl)