HI Dave,

> I am writing a fairly simply stateless redirect server.  It is
> multithreaded, where the main thread creates the root task and runs the
> thread loop, and receives incoming SIP invites.  If I simply respond to the
> INVITE with nta_msg_treply in the main thread, everything works.  However,
> if from the main thread I send a message (su_msg_send) to a clone task, with
> the message containing the msg_t and sip_t, and then from the clone do the
> lookup of the contact header I want to use, and (finally) then from the
> clone task send a reply message back to the main thread.....now when the
> main thread calls nta_msg_treply I get either a log message saying "mreply:
> cannot complete message", or it crashes.  This is the case even if I simply
> try to send a 404 Not Found (i.e. ignoring the contact the worker thread is
> bringing back).
>
> It seems like passing the msg_t and sip_t objects out of the main thread --
> and using them beyond the lifespan of the sip message callback -- is the
> only difference I can see between the two scenarios.  So my question is, do
> I need to do something to be able to continue to have access to the
> parameters passed to me in the  stateless callback function after the time
> when that function returns?  Or am I doing something else wrong?
>
>
I was actually using more or less same approach as yours in my app. Also
multi-threaded application with NTA, but I was using stateful approach, not
stateless. In my stateful application, I pass the sip_t and nta_incoming_t
objects to the clone task using su_msg_send(), but then I do not pass them
back to the main thread. When I want to reply from the clone task. I just
do:

 su_root_obtain(root_object);
 {
      nta_incoming_treply(....) --> Would be nta_msg_treply() in your case
here
 }
 su_root_release(root_object);

Obtaining/Releasing the root object is like locking/unlocking the NTA agent,
so you can just reply from the clone task after you make sure the main
thread (or any other thread) doesn't use the NTA agent for anything. BTW, if
your main thread also does other things apart from receiving incoming
requests, like callback executions on timeouts which don't use the NTA
agent, you can su_root_release() at the beginning of the callback and
su_root_obtain() before exiting the callback, so that the clone tasks can
reply themselves while the main thread is doing other things not NTA-agent
related.

About the specific problem you have, I really can't help much, as I didn't
see it before. But your way of doing it is quite similar to my way, with the
only difference of the stateless/stateful approaches, so maybe you can give
it a try.


Also, once I do generate a final response, is it my responsibility to do
> anything to clear the memory associated with the objects related to that
> message (the sip_t and msg_t parameters I got from the stateless callback)
>
>
No, you don't need anything else. When you call either nta_msg_treply(),
nta_msg_tsend() or nta_msg_discard(), the request is marked as processed in
the NTA agent, and will be freed by the agent internals after some time.


Pekka, please correct me if anything wrong.

Cheers,
-Aleksander
------------------------------------------------------------------------------
This SF.Net email is sponsored by the Verizon Developer Community
Take advantage of Verizon's best-in-class app development support
A streamlined, 14 day to market process makes app distribution fast and easy
Join now and get one step closer to millions of Verizon customers
http://p.sf.net/sfu/verizon-dev2dev 
_______________________________________________
Sofia-sip-devel mailing list
Sofia-sip-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sofia-sip-devel

Reply via email to