Re: passing parameter by reference?
- From: Neil Madden <nem@xxxxxxxxxxxxx>
- Date: Tue, 29 Nov 2005 02:24:55 GMT
Lisa Pearlson wrote:
... in essence it's 1 process listening on several sockets simultaneously and as such the global variables are shared among all those clients.. somehow I would have to keep an associative array with the key being the socket descriptor and value being an array of variables I wish to track for each client, such as a timerid for the idle timeout handling of each connection, etc. This is too much overhead I think.
It's not that much overhead. Something simple along the lines of:
proc readData {chan ...} {
global state
puts "The timeput on $chan is $state($chan,timeout)"
...
}That should work fine, and is an approach I have used on several occassions.
As you are using fileevents, another method is to reschedule the fileevent with the updated state:
proc readData {chan chanState ...} {
array set state $chanState
puts "The timeout on $chan is $state(timeout)"
...
fileevent $chan readable \
[list readData $chan [array get state]...]
}Which is quite neat in some ways (e.g. closing the channel will delete the fileevent and automatically clean up the state for you), but I'd probably go with the global array first.
-- Neil .
- References:
- passing parameter by reference?
- From: Lisa Pearlson
- Re: passing parameter by reference?
- From: Gerald W. Lester
- Re: passing parameter by reference?
- From: Lisa Pearlson
- passing parameter by reference?
- Prev by Date: Re: Combo box command and default value
- Next by Date: string handle problem
- Previous by thread: Re: passing parameter by reference?
- Next by thread: Re: passing parameter by reference?
- Index(es):
Relevant Pages
|