<div dir="ltr"><div>Hi,<br></div><div><br></div><div>Just a note about the issue of removing a source after it was triggered but not yet dispatched, although I'm not sure this will help in your case, you should always call the following code in a source callback function :</div>

<div>if (g_source_is_destroyed(g_main_current_source()) {</div><div>  return;</div><div>}</div><div><br></div><div>I believe libnice already checks that before calling the callback, so you may not need to. It's a nice trick to know though. See the documentation for g_source_is_destroyed.</div>
<div><br></div><div>Youness.</div><div><br></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Mon, Jul 7, 2014 at 3:17 AM, Philip Withnall <span dir="ltr"><<a href="mailto:philip@tecnocode.co.uk" target="_blank">philip@tecnocode.co.uk</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi,<br>
<br>
To ensure you receive no more callbacks for an agent, call<br>
nice_agent_remove_stream() on all the agent's streams.<br>
<br>
If you ever want to re-add the agent to the main loop, then using<br>
nice_agent_attach_recv() with a null callback should work.<br>
<br>
If, after trying the first option, you are still receiving the callback<br>
after destroying the user, please provide us with a backtrace of the<br>
crash.<br>
<br>
A note about main loops: g_main_loop_quit() does not 'pause' the loop,<br>
it stops it completely, *after* the current loop iteration has<br>
completed. If T1 does not exit from g_main_loop_run() after you have<br>
called g_main_loop_quit() from T2, then there is a bug in your code. You<br>
are correct in thinking that pending sources will remain in the main<br>
context after you have quit the main loop, and will be dispatched if the<br>
loop is run again.<br>
<span class="HOEnZb"><font color="#888888"><br>
Philip<br>
</font></span><div class="HOEnZb"><div class="h5"><br>
On Mon, 2014-07-07 at 08:40 +0200, Emanuele Bizzarri wrote:<br>
> Hi,<br>
> I'm using libnice in order to forward rtp data among users into a star<br>
> topology network.<br>
> When one user joins, he starts to send and receive data to and from<br>
> other users.<br>
> The server forwards packets among users.<br>
> When he quit I have to remove and destroy the user reference.<br>
> But how can I be sure that the nice_agent_attach_recv callback will not<br>
> longer triggered?<br>
> Sometimes my application crashes inside the callback after I've<br>
> destroyed the user.<br>
><br>
> I'm  using a dedicated thread (T1) to manage g_main_loop_run (it is a<br>
> blocking function).<br>
> Then user is destroyed by another thread (T2).<br>
> I have tried to pause the loop using g_main_loop_quit (from T2) and wait<br>
> T1 exiting from g_main_loop_run but without success.<br>
> Probably there are pending sources/events already dispatched and when I<br>
> rerun the loop they will be triggered.<br>
> I've tried to call nice_agent_attach_recv with null callback before<br>
> destroy the user, but the problem still remains.<br>
><br>
> Can you help me please?<br>
><br>
> Which is the correct way to add and remove an agent from a loop that<br>
> manage multiple agents?<br>
><br>
> Thank you in advance,<br>
><br>
> Emanuele<br>
><br>
><br>
> _______________________________________________<br>
> nice mailing list<br>
> <a href="mailto:nice@lists.freedesktop.org">nice@lists.freedesktop.org</a><br>
> <a href="http://lists.freedesktop.org/mailman/listinfo/nice" target="_blank">http://lists.freedesktop.org/mailman/listinfo/nice</a><br>
<br>
</div></div><br>_______________________________________________<br>
nice mailing list<br>
<a href="mailto:nice@lists.freedesktop.org">nice@lists.freedesktop.org</a><br>
<a href="http://lists.freedesktop.org/mailman/listinfo/nice" target="_blank">http://lists.freedesktop.org/mailman/listinfo/nice</a><br>
<br></blockquote></div><br></div>