[libnice] Is there any non-blocking method corresponding to g_main_loop_run()?

Philip Withnall philip at tecnocode.co.uk
Thu Dec 3 16:07:03 PST 2015


Hey,

On Mon, 2015-11-30 at 20:33 +0800, Jack Wang wrote:
> I'm trying to implement ICE on SIP,
> I reference the sdp-example of libnice and want to apply it to my SIP
> codes.
> 
> The example uses the standard IO to exchange the SDPs,
> but in SIP it needs to listen the response from other side.
> 
> The question is, before I send INVITE I have to gather ICE
> candidates,
> and wait for signals to proceed. This will block the main process by
> g_main_loop_run(),
> so the SIP procedure can't be triggered normally.
> 
> But if I remove the g_main_loop_run(),according to the line 162 in
> the example above:
> 
> while (!exit_thread && !candidate_gathering_done)
> this candidate_gathering_done will never be assigned since the signal
> fail to get through callback function. Is there any non-blocking way
> to multiplex ICE and SIP procedures?

You can either use threads, as Curieux Tres suggested, which means you
have to be very careful about thread safety, or:

You can run your entire program inside the main loop. Run
g_main_loop_run() in main(), and don’t do anything else in main().
Start your first operation from a g_idle_add() callback, and connect to
whatever signals you want to wait for from the end of that callback.
Since everything is running inside g_main_loop_run(), this means the
signals will be processed.

Think of g_main_loop_run() as a poll() call. This is how it is meant to
be used. The way that sdp-example uses it, iterating it manually and
mixing it with threads and condition variables, is pretty horrific and
totally not the way to use GMainLoop.

There’s some documentation on GMainLoop and related APIs here:
 • https://developer.gnome.org/glib/stable/glib-The-Main-Event-Loop.htm
l
 • https://developer.gnome.org/programming-guidelines/unstable/main-con
texts.html.en

Philip
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 213 bytes
Desc: This is a digitally signed message part
URL: <http://lists.freedesktop.org/archives/nice/attachments/20151204/db18a9f6/attachment.sig>


More information about the nice mailing list