summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOlivier Crête <olivier.crete@collabora.com>2016-01-15 22:40:27 -0500
committerOlivier Crête <olivier.crete@collabora.com>2016-05-30 19:16:34 -0400
commit1949b89f3de6e45616187e86f542d26a003ea7a6 (patch)
tree00d841b7626b7d2f49406d3085e8b6c364ad30fb
parent93330f1f97e4f2a9ff09b602765e620cb279574b (diff)
downloadlibnice-1949b89f3de6e45616187e86f542d26a003ea7a6.tar.gz
component: Add API to cleanly remove a base socket
-rw-r--r--agent/agent.c2
-rw-r--r--agent/component.c49
-rw-r--r--agent/component.h3
3 files changed, 48 insertions, 6 deletions
diff --git a/agent/agent.c b/agent/agent.c
index 98f6ec3..2f25db6 100644
--- a/agent/agent.c
+++ b/agent/agent.c
@@ -4872,7 +4872,7 @@ component_io_cb (GSocket *gsocket, GIOCondition condition, gpointer user_data)
stream->id, component->id, NICE_COMPONENT_STATE_FAILED);
}
- nice_component_detach_socket (component, socket_source->socket);
+ nice_component_remove_socket (component, socket_source->socket);
agent_unlock ();
g_object_unref (agent);
return G_SOURCE_REMOVE;
diff --git a/agent/component.c b/agent/component.c
index f90ba82..1e9cddd 100644
--- a/agent/component.c
+++ b/agent/component.c
@@ -82,6 +82,10 @@ static void
nice_component_schedule_io_callback (NiceComponent *component);
static void
nice_component_deschedule_io_callback (NiceComponent *component);
+static void
+nice_component_detach_socket (NiceComponent *component, NiceSocket *nicesock);
+static void
+nice_component_clear_selected_pair (NiceComponent *component);
void
@@ -153,6 +157,45 @@ nice_component_new (guint id, NiceAgent *agent, NiceStream *stream)
}
void
+nice_component_remove_socket (NiceComponent *cmp, NiceSocket *nsocket)
+{
+ GSList *i;
+
+ for (i = cmp->local_candidates; i;) {
+ NiceCandidate *candidate = i->data;
+ GSList *next = i->next;
+
+ if (!nice_socket_is_based_on (candidate->sockptr, nsocket)) {
+ i = next;
+ continue;
+ }
+
+ if (candidate == cmp->selected_pair.local) {
+ nice_component_clear_selected_pair (cmp);
+ agent_signal_component_state_change (cmp->agent, cmp->stream->id,
+ cmp->id, NICE_COMPONENT_STATE_FAILED);
+ }
+
+ refresh_prune_candidate (cmp->agent, candidate);
+ if (candidate->sockptr != nsocket) {
+ discovery_prune_socket (cmp->agent, candidate->sockptr);
+ conn_check_prune_socket (cmp->agent, cmp->stream, cmp,
+ candidate->sockptr);
+ nice_component_detach_socket (cmp, candidate->sockptr);
+ }
+ agent_remove_local_candidate (cmp->agent, candidate);
+ nice_candidate_free (candidate);
+
+ cmp->local_candidates = g_slist_delete_link (cmp->local_candidates, i);
+ i = next;
+ }
+
+ discovery_prune_socket (cmp->agent, nsocket);
+ conn_check_prune_socket (cmp->agent, cmp->stream, cmp, nsocket);
+ nice_component_detach_socket (cmp, nsocket);
+}
+
+void
nice_component_clean_turn_servers (NiceComponent *cmp)
{
GSList *i;
@@ -541,7 +584,7 @@ nice_component_reattach_all_sockets (NiceComponent *component)
/**
* nice_component_detach_socket:
- * @component: a #Component
+ * @component: a #NiceComponent
* @socket: the socket to detach the source for
*
* Detach the #GSource for the single specified @socket. It also closes it
@@ -549,7 +592,7 @@ nice_component_reattach_all_sockets (NiceComponent *component)
*
* If the @socket doesn’t exist in this @component, do nothing.
*/
-void
+static void
nice_component_detach_socket (NiceComponent *component, NiceSocket *nicesock)
{
GSList *l;
@@ -1281,7 +1324,7 @@ static GSourceFuncs component_source_funcs = {
};
/**
- * component_source_new:
+ * nice_component_source_new:
* @agent: a #NiceAgent
* @stream_id: The stream's id
* @component_id: The component's number
diff --git a/agent/component.h b/agent/component.h
index 0cc6211..6712794 100644
--- a/agent/component.h
+++ b/agent/component.h
@@ -261,8 +261,7 @@ void
nice_component_attach_socket (NiceComponent *component, NiceSocket *nsocket);
void
-nice_component_detach_socket (NiceComponent *component, NiceSocket *nsocket);
-
+nice_component_remove_socket (NiceComponent *component, NiceSocket *nsocket);
void
nice_component_detach_all_sockets (NiceComponent *component);