static GCond *stun_thread_signal_ptr = &stun_thread_signal;
#endif
-static GMainLoop *global_mainloop;
static NiceComponentState global_lagent_state = NICE_COMPONENT_STATE_LAST;
static NiceComponentState global_ragent_state = NICE_COMPONENT_STATE_LAST;
+static GCancellable *global_cancellable;
static gboolean exit_stun_thread = FALSE;
static gboolean lagent_candidate_gathering_done = FALSE;
static gboolean ragent_candidate_gathering_done = FALSE;
static guint global_ls_id, global_rs_id;
static gboolean data_received = FALSE;
static gboolean drop_stun_packets = FALSE;
+static gboolean got_stun_packet = FALSE;
+static gboolean send_stun = FALSE;
static const uint16_t known_attributes[] = {
0
buf_len = stun_agent_finish_message (agent, &response, NULL, 0);
send_buf:
- g_main_loop_quit (global_mainloop);
+ g_cancellable_cancel (global_cancellable);
g_debug ("Ready to send a STUN response");
g_assert (g_mutex_trylock (stun_mutex_ptr));
- while (global_lagent_state < NICE_COMPONENT_STATE_CONNECTING) {
+ got_stun_packet = TRUE;
+ while (send_stun) {
g_debug ("Waiting for signal. State is %d", global_lagent_state);
g_cond_wait (stun_signal_ptr, stun_mutex_ptr);
}
g_debug ("ragent finished gathering candidates");
ragent_candidate_gathering_done = TRUE;
}
- g_main_loop_quit(global_mainloop);
+ g_cancellable_cancel (global_cancellable);
}
static void cb_nice_recv (NiceAgent *agent, guint stream_id, guint component_id, guint len, gchar *buf, gpointer user_data)
g_debug ("test-dribblemode:%s: ragent recieved %d bytes : quit mainloop",
G_STRFUNC, len);
data_received = TRUE;
- g_main_loop_quit (global_mainloop);
+ g_cancellable_cancel (global_cancellable);
}
}
if (GPOINTER_TO_UINT(data) == 1 && state == NICE_COMPONENT_STATE_FAILED) {
g_debug ("Signalling STUN response since connchecks failed");
g_mutex_lock (stun_mutex_ptr);
+ send_stun = TRUE;
g_cond_signal (stun_signal_ptr);
g_mutex_unlock (stun_mutex_ptr);
- g_main_loop_quit (global_mainloop);
+ g_cancellable_cancel (global_cancellable);
}
if(GPOINTER_TO_UINT(data) == 1 && state == NICE_COMPONENT_STATE_READY) {
if (signal_stun_reply) {
g_mutex_lock (stun_mutex_ptr);
+ send_stun = TRUE;
g_cond_signal (stun_signal_ptr);
g_mutex_unlock (stun_mutex_ptr);
}
}
data_received = FALSE;
+ got_stun_packet = FALSE;
+ send_stun = FALSE;
nice_agent_attach_recv (lagent, global_ls_id, NICE_COMPONENT_TYPE_RTP,
- g_main_loop_get_context(global_mainloop),
+ g_main_context_default (),
cb_nice_recv, LEFT_AGENT);
nice_agent_attach_recv (ragent, global_rs_id, NICE_COMPONENT_TYPE_RTP,
- g_main_loop_get_context(global_mainloop),
+ g_main_context_default (),
cb_nice_recv, RIGHT_AGENT);
}
{
g_debug ("test-dribblemode:%s", G_STRFUNC);
+ got_stun_packet = FALSE;
init_test (lagent, ragent, FALSE);
nice_agent_gather_candidates (lagent, global_ls_id);
- g_main_loop_run (global_mainloop);
+ while (!got_stun_packet)
+ g_main_context_iteration (NULL, TRUE);
g_assert (global_lagent_state == NICE_COMPONENT_STATE_GATHERING &&
!lagent_candidate_gathering_done);
nice_agent_gather_candidates (ragent, global_rs_id);
- if (!ragent_candidate_gathering_done) {
- g_main_loop_run (global_mainloop);
- g_assert (ragent_candidate_gathering_done);
- }
+ while (!ragent_candidate_gathering_done)
+ g_main_context_iteration (NULL, TRUE);
+ g_cancellable_reset (global_cancellable);
+ g_assert (ragent_candidate_gathering_done);
set_credentials (lagent, global_ls_id, ragent, global_rs_id);
lagent, global_ls_id,
TRUE);
- g_main_loop_run (global_mainloop);
+ while (!data_received)
+ g_main_context_iteration (NULL, TRUE);
+ g_cancellable_reset (global_cancellable);
g_assert (global_lagent_state >= NICE_COMPONENT_STATE_CONNECTED &&
data_received);
swap_candidates (lagent, global_ls_id,
ragent, global_rs_id,
FALSE);
- g_main_loop_run (global_mainloop);
+ while (!lagent_candidate_gathering_done)
+ g_main_context_iteration (NULL, TRUE);
+ g_cancellable_reset (global_cancellable);
g_assert (lagent_candidate_gathering_done);
"wrong2", "wrong2");
nice_agent_gather_candidates (lagent, global_ls_id);
- g_main_loop_run (global_mainloop);
+ while (!got_stun_packet)
+ g_main_context_iteration (NULL, TRUE);
+ g_cancellable_reset (global_cancellable);
g_assert (global_lagent_state == NICE_COMPONENT_STATE_GATHERING &&
!lagent_candidate_gathering_done);
nice_agent_gather_candidates (ragent, global_rs_id);
- if (!ragent_candidate_gathering_done) {
- g_main_loop_run (global_mainloop);
- g_assert (ragent_candidate_gathering_done);
- }
+ while (!ragent_candidate_gathering_done)
+ g_main_context_iteration (NULL, TRUE);
+ g_cancellable_reset (global_cancellable);
+ g_assert (ragent_candidate_gathering_done);
swap_candidates (ragent, global_rs_id,
lagent, global_ls_id,
FALSE);
- g_main_loop_run (global_mainloop);
- g_assert (global_lagent_state == NICE_COMPONENT_STATE_FAILED);
+ while (global_lagent_state != NICE_COMPONENT_STATE_FAILED)
+ g_main_context_iteration (NULL, TRUE);
+ g_cancellable_reset (global_cancellable);
// Set the correct credentials and swap candidates
set_credentials (lagent, global_ls_id, ragent, global_rs_id);
ragent, global_rs_id,
FALSE);
- g_main_loop_run (global_mainloop);
+ while (!data_received)
+ g_main_context_iteration (NULL, TRUE);
+ g_cancellable_reset (global_cancellable);
g_assert (data_received);
g_assert (global_lagent_state == NICE_COMPONENT_STATE_READY);
g_assert (global_ragent_state >= NICE_COMPONENT_STATE_CONNECTED);
// Wait for lagent to finish gathering candidates
- g_main_loop_run (global_mainloop);
+ while (!lagent_candidate_gathering_done)
+ g_main_context_iteration (NULL, TRUE);
+ g_cancellable_reset (global_cancellable);
+
g_assert (lagent_candidate_gathering_done);
cleanup (lagent, ragent);
init_test (lagent, ragent, FALSE);
nice_agent_gather_candidates (lagent, global_ls_id);
- g_main_loop_run (global_mainloop);
+ while (!got_stun_packet)
+ g_main_context_iteration (NULL, TRUE);
+ g_cancellable_reset (global_cancellable);
g_assert (global_lagent_state == NICE_COMPONENT_STATE_GATHERING &&
!lagent_candidate_gathering_done);
nice_agent_gather_candidates (ragent, global_rs_id);
- if (!ragent_candidate_gathering_done) {
- g_main_loop_run (global_mainloop);
- g_assert (ragent_candidate_gathering_done);
- }
+ while (!ragent_candidate_gathering_done)
+ g_main_context_iteration (NULL, TRUE);
+ g_cancellable_reset (global_cancellable);
+
+ g_assert (ragent_candidate_gathering_done);
add_bad_candidate (lagent, global_ls_id, cand);
// lagent will finish candidate gathering causing this mainloop to quit
- g_main_loop_run (global_mainloop);
+ while (!lagent_candidate_gathering_done)
+ g_main_context_iteration (NULL, TRUE);
+ g_cancellable_reset (global_cancellable);
// connchecks will fail causing this mainloop to quit
- g_main_loop_run (global_mainloop);
+ while (global_lagent_state != NICE_COMPONENT_STATE_FAILED)
+ g_main_context_iteration (NULL, TRUE);
+ g_cancellable_reset (global_cancellable);
g_assert (global_lagent_state == NICE_COMPONENT_STATE_FAILED &&
!data_received);
ragent, global_rs_id,
FALSE);
- g_main_loop_run (global_mainloop);
+ while (!data_received)
+ g_main_context_iteration (NULL, TRUE);
+ g_cancellable_reset (global_cancellable);
g_assert (lagent_candidate_gathering_done);
- g_assert (global_lagent_state == NICE_COMPONENT_STATE_READY);
+ g_assert (global_lagent_state >= NICE_COMPONENT_STATE_CONNECTED);
g_assert (global_ragent_state >= NICE_COMPONENT_STATE_CONNECTED);
cleanup (lagent, ragent);
set_credentials (lagent, global_ls_id, ragent, global_rs_id);
nice_agent_gather_candidates (lagent, global_ls_id);
- g_main_loop_run (global_mainloop);
+ while (!got_stun_packet)
+ g_main_context_iteration (NULL, TRUE);
+ g_cancellable_reset (global_cancellable);
g_assert (global_lagent_state == NICE_COMPONENT_STATE_GATHERING &&
!lagent_candidate_gathering_done);
nice_agent_gather_candidates (ragent, global_rs_id);
- if (!ragent_candidate_gathering_done) {
- g_main_loop_run (global_mainloop);
- }
+ while (!ragent_candidate_gathering_done)
+ g_main_context_iteration (NULL, TRUE);
+ g_cancellable_reset (global_cancellable);
// Wait for data
- g_main_loop_run (global_mainloop);
+ while (!data_received)
+ g_main_context_iteration (NULL, TRUE);
+ g_cancellable_reset (global_cancellable);
g_assert (data_received);
// Data arrived, signal STUN thread to send STUN response
g_mutex_lock (stun_mutex_ptr);
+ send_stun = TRUE;
g_cond_signal (stun_signal_ptr);
g_mutex_unlock (stun_mutex_ptr);
// Wait for lagent to finish gathering candidates
- g_main_loop_run (global_mainloop);
+ while (!lagent_candidate_gathering_done ||
+ !lagent_candidate_gathering_done)
+ g_main_context_iteration (NULL, TRUE);
+ g_cancellable_reset (global_cancellable);
g_assert (lagent_candidate_gathering_done);
g_assert (ragent_candidate_gathering_done);
NiceAgent *lagent = NULL, *ragent = NULL;
GThread *stun_thread = NULL;
NiceAddress baseaddr;
+ GSource *src;
g_type_init();
- global_mainloop = g_main_loop_new (NULL, FALSE);
+ global_cancellable = g_cancellable_new ();
+ src = g_cancellable_source_new (global_cancellable);
+ g_source_set_dummy_callback (src);
+ g_source_attach (src, NULL);
+ g_source_unref (src);
#if !GLIB_CHECK_VERSION(2,31,8)
g_thread_init (NULL);
- stun_thread = g_thread_create (stun_thread_func,
- global_mainloop,
- TRUE, NULL);
+ stun_thread = g_thread_create (stun_thread_func, NULL, TRUE, NULL);
stun_mutex_ptr = g_mutex_new ();
stun_signal_ptr = g_cond_new ();
#else
g_mutex_lock (stun_thread_mutex_ptr);
g_cond_wait (stun_thread_signal_ptr, stun_thread_mutex_ptr);
- lagent = nice_agent_new (g_main_loop_get_context (global_mainloop),
- NICE_COMPATIBILITY_RFC5245);
- ragent = nice_agent_new (g_main_loop_get_context (global_mainloop),
- NICE_COMPATIBILITY_RFC5245);
+ lagent = nice_agent_new (NULL, NICE_COMPATIBILITY_RFC5245);
+ ragent = nice_agent_new (NULL, NICE_COMPATIBILITY_RFC5245);
g_object_set (G_OBJECT (lagent), "controlling-mode", TRUE, NULL);
g_object_set (G_OBJECT (ragent), "controlling-mode", FALSE, NULL);
g_mutex_free (stun_mutex_ptr);
g_cond_free (stun_signal_ptr);
#endif
- g_main_loop_unref (global_mainloop);
+ g_object_unref (global_cancellable);
return 0;
}