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

Jack Wang antirazin at gmail.com
Wed Dec 9 17:36:41 PST 2015


Sorry for the late reply:P

I take Curieux Tres's advice and create a new thread to run g_main_loop_run
and it works!
Other operations will never be blocked anymore.

Thank you guys for the great answers :)


2015-12-04 8:07 GMT+08:00 Philip Withnall <philip at tecnocode.co.uk>:

> 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
> _______________________________________________
> nice mailing list
> nice at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/nice
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freedesktop.org/archives/nice/attachments/20151210/97a640d5/attachment.html>


More information about the nice mailing list