Re: [Sofia-sip-devel] Question aboiut NTA and sip_t
Hi Pete, I have read through all your posts on the mailing list and I would > like to implement the same 1 listener , multiple worker model that you > are mentioning here. > > I have question about how to use the SU api to sprawn thread for each > incoming INVITE. Can you please share with me the structure of your > code? > > Although I cannot share the code here, the main idea was the following: * Get incoming messages in the primary thread (listener one). * In our case, that message was kind of encapsulated in some other object (GLib's GObjects) * Using su_msg_send, pass the object to another sofia-sip 'clone', which was implemented as a thread (I believe you could configure if you wanted clones to be threads or just other main loops in the same thread). * Process the message in the sofia-sip clone. But considering that if you want to reply, for example (or actually use any other method against the nta_t), you need to acquire the root of the main primary thread. Kind of acquiring the mutex so that noone else is touching the NTA while you set the reply. Replies, as far as I can remember, are then sent by the main thread (this is, when you set the reply, you just leave it there so that when main thread gets the control of its own root, it will really send it). * So one of the key points here is that in order this to work, your main thread needs to yield its root when it's not using it. In our case it was kind of easy, as we could yield the root to be used by others when making some initial checks to the received message in the main thread, and such. I remember that we did some other optimizations to that, but can't remember quite well. Anyway, I cannot remember many details about it, and currently I don't work in the company involved in SIP stuff, so can't get much details of how we did it. If you want some advice, try to avoid mixing sofia-sip code with other general-purpose library like GLib (as we did). Better spend some time looking at sofia-sip documentation, sofia-sip source code (when documentation is not very much, as in the case of clones and su_msg_send and stuff), and try to stick to using sofia-sip based objects, memory homes and friends. I really felt like opening Pandora's box when started to implement the thread-based app with sofia-sip, but after a while it was quite fun and it ended up working pretty well (300 threads in parallel). Cheers! -- Aleksander -- ThinkGeek and WIRED's GeekDad team up for the Ultimate GeekDad Father's Day Giveaway. ONE MASSIVE PRIZE to the lucky parental unit. See the prize list and enter to win: http://p.sf.net/sfu/thinkgeek-promo___ Sofia-sip-devel mailing list Sofia-sip-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/sofia-sip-devel
Re: [Sofia-sip-devel] Question aboiut NTA and sip_t
Hi Aleksander, I have read through all your posts on the mailing list and I would like to implement the same 1 listener , multiple worker model that you are mentioning here. I have question about how to use the SU api to sprawn thread for each incoming INVITE. Can you please share with me the structure of your code? Thanks you so much. Pete On Wed, Sep 23, 2009 at 10:12 AM, Aleksander Morgado wrote: > Hi Daniel, > >> >> When NTA receives a request which doesn't match an existing transaction it >> passes a pointer to the callback function of type sip_t. Can this pointer >> be dereferenced through the lifetime of the transaction or does it go poof >> as soon as I exit the callback function? >> > > My understanding is that the pointer to the sip_t struct can be used as long > as you don't set a reply to the SIP message. > >> >> I ask because I'm writing a multi-threaded UAS which has to pass some >> objects from the callback function on to another thread. The callback >> function exits while the other thread is busy processing the request. I >> need to know if I have to make a copy of whatever sip_t * points to first >> before I pass it along for processing. >> > > I use same approach, with a "listener thread" getting all requests and > passing them to several "worker threads", using sofia-sip built-in clones > and communication based on su_msg_r structures. Take care, because you must > synchronize the access to the nta object when replying the incoming > transactions from the threads. You can't just call nta_incoming_treply() > from another thread and think it will internally sync access to the members > of the nta object, which is used by all threads. You can synchronize it > "obtaining" and "releasing" the root object where the nta object is attached > to. > > Cheers, > -Aleksander > > -- > Come build with us! The BlackBerry® Developer Conference in SF, CA > is the only developer event you need to attend this year. Jumpstart your > developing skills, take BlackBerry mobile applications to market and stay > ahead of the curve. Join us from November 9-12, 2009. Register now! > http://p.sf.net/sfu/devconf > ___ > Sofia-sip-devel mailing list > Sofia-sip-devel@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/sofia-sip-devel > > -- ThinkGeek and WIRED's GeekDad team up for the Ultimate GeekDad Father's Day Giveaway. ONE MASSIVE PRIZE to the lucky parental unit. See the prize list and enter to win: http://p.sf.net/sfu/thinkgeek-promo ___ Sofia-sip-devel mailing list Sofia-sip-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/sofia-sip-devel
Re: [Sofia-sip-devel] Question aboiut NTA and sip_t
2009/9/9 Daniel Corbe : > When NTA receives a request which doesn't match an existing transaction it > passes a pointer to the callback function of type sip_t. Can this pointer be > dereferenced through the lifetime of the transaction or does it go poof as > soon as I exit the callback function? As Aleksander said, you can use sip_t as long as the transaction is alive. The sip_t pointer lives inside an abstract msg_t container and you can also get a new reference to it with nta_incoming_getrequest(). After you are done with your sip_t / msg_t reference, you should remove the reference with msg_destroy(). -- Pekka.Pessi mail at nokia.com -- Come build with us! The BlackBerry® Developer Conference in SF, CA is the only developer event you need to attend this year. Jumpstart your developing skills, take BlackBerry mobile applications to market and stay ahead of the curve. Join us from November 9-12, 2009. Register now! http://p.sf.net/sfu/devconf ___ Sofia-sip-devel mailing list Sofia-sip-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/sofia-sip-devel
Re: [Sofia-sip-devel] Question aboiut NTA and sip_t
Hi Daniel, > When NTA receives a request which doesn't match an existing transaction it > passes a pointer to the callback function of type sip_t. Can this pointer > be dereferenced through the lifetime of the transaction or does it go poof > as soon as I exit the callback function? > > My understanding is that the pointer to the sip_t struct can be used as long as you don't set a reply to the SIP message. > I ask because I'm writing a multi-threaded UAS which has to pass some > objects from the callback function on to another thread. The callback > function exits while the other thread is busy processing the request. I > need to know if I have to make a copy of whatever sip_t * points to first > before I pass it along for processing. > > I use same approach, with a "listener thread" getting all requests and passing them to several "worker threads", using sofia-sip built-in clones and communication based on su_msg_r structures. Take care, because you must synchronize the access to the nta object when replying the incoming transactions from the threads. You can't just call nta_incoming_treply() from another thread and think it will internally sync access to the members of the nta object, which is used by all threads. You can synchronize it "obtaining" and "releasing" the root object where the nta object is attached to. Cheers, -Aleksander -- Come build with us! The BlackBerry® Developer Conference in SF, CA is the only developer event you need to attend this year. Jumpstart your developing skills, take BlackBerry mobile applications to market and stay ahead of the curve. Join us from November 9-12, 2009. Register now! http://p.sf.net/sfu/devconf___ Sofia-sip-devel mailing list Sofia-sip-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/sofia-sip-devel
[Sofia-sip-devel] Question aboiut NTA and sip_t
Hello list, When NTA receives a request which doesn't match an existing transaction it passes a pointer to the callback function of type sip_t. Can this pointer be dereferenced through the lifetime of the transaction or does it go poof as soon as I exit the callback function? I ask because I'm writing a multi-threaded UAS which has to pass some objects from the callback function on to another thread. The callback function exits while the other thread is busy processing the request. I need to know if I have to make a copy of whatever sip_t * points to first before I pass it along for processing. Thanks. Regards, Daniel -- Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day trial. Simplify your report design, integration and deployment - and focus on what you do best, core application coding. Discover what's new with Crystal Reports now. http://p.sf.net/sfu/bobj-july ___ Sofia-sip-devel mailing list Sofia-sip-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/sofia-sip-devel