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

Reply via email to