Am 18.03.2013 22:30, schrieb Julian Wiesener:
> Hi,
>
> On Mon, 2013-03-18 at 08:09 +0100, Jean-Michel Caricand wrote:
>> How can I read a session variable from a C++ function.
> in short: you can't.
> longer: you could try to use the tntnet-internal functions to access
> variables from the session scope, but then you'll need to know which
> session id the request have and you can't access the request object from
> your function.
>
> What you need to do is, to pass the session variable to the function,
> preferable by reference.
>
> My component :
>
> mycomp.ecpp :
>
> ...
> <%session>
> int myvariable;
> </%session>
>
> myfunction(myvariable)
> ...
>
> myfunction.cpp :
>
> void myfunction(int& _myvariable)
> {
>      _myvariable = //whatever
>      ...
>      ...
> }
>
>
> Regards,
> Julian
>
Thats exactly what I wanted to say. The problem is, that there is no one 
single instance of the session variable. The session variable will be 
created when a request is executed and will be destroyed, when the 
session is timed out. When another user executes a request, another 
instance of the variable is created. So there can't be "the" session 
variable. The only solution is really to pass it by reference. And don't 
try to store a pointer to the variable somewhere. It might be destroyed 
when the session times out and your pointer points to nowhere.

Tommi

------------------------------------------------------------------------------
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:
http://p.sf.net/sfu/appdyn_d2d_mar
_______________________________________________
Tntnet-general mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tntnet-general

Reply via email to