Forum Discussion

jeff_mccombs_47's avatar
jeff_mccombs_47
Icon for Nimbostratus rankNimbostratus
Aug 05, 2009

when EVENT "chaining" and variable scope.

If you do something like:

 
 when HTTP_REQUEST priority 1 { 
   set somevar "somevalue" 
 } 
 

Is the variable accessable in other HTTP_REQUEST event blocks with a higher priority?

does that make sense? Does the Tcl interp "chain" events together, executing each event independently in a seperate namespace in order of priority, or does it concatenate them all and execute them under the same namespace?

Obviously, local variables set in each event probably aren't transferrable - that is, I can't access $somevar under a HTTP_RESPONSE event unless it was global when it was declared. But events of the same type fired sequentially.. what happens then?

2 Replies

  • I believe if they are declared at the highest priority they can be used at the lower priority ones. However, they must adhere to the contruction and interaction as they remain usable as long as the connection remains present. If the events are triggered across different connections then a global variable should be used.
  • You could test this pretty easily:

     
     when HTTP_REQUEST priority 1 { 
      
         This will trigger a runtime TCL error as the variable doesn't exist 
        log local0. "\$non_existent_variable: $non_existent_variable" 
      
         Comment out the above and set the variable in this event 
        set non_existent_variable "now exists!" 
     } 
     when HTTP_REQUEST priority 2 { 
      
         This will work now 
        log local0. "\$non_existent_variable: $non_existent_variable" 
     } 
     

    does that make sense? Does the Tcl interp "chain" events together, executing each event independently in a seperate namespace in order of priority, or does it concatenate them all and execute them under the same namespace?

    I think each event on the same virtual server is chained together in order of priority under the same namespace.

    Obviously, local variables set in each event probably aren't transferrable - that is, I can't access $somevar under a HTTP_RESPONSE event unless it was global when it was declared. But events of the same type fired sequentially.. what happens then?

    As cmbhatt said, yes, you can access a local variable across the same TCP connection in different events as long as the event you're referencing the variable in occurs after the local variable was set.

    Aaron