Commit a2a4b49e authored by Dafydd Harries's avatar Dafydd Harries

nice_agent_remove_stream ()

darcs-hash:20070209142622-c9803-90f998b0f262523335a9866e669af8abea1b6504.gz
parent b7fcf07e
......@@ -29,7 +29,7 @@ libagent_la_LIBADD = \
check_PROGRAMS = \
test \
test-add-stream \
test-add-remove-stream \
test-recv \
test-send \
test-stun \
......@@ -40,7 +40,7 @@ TESTS = $(check_PROGRAMS)
test_LDADD = libagent.la $(GLIB_LIBS)
test_add_stream_LDADD = $(COMMON_LDADD)
test_add_remove_stream_LDADD = $(COMMON_LDADD)
test_recv_LDADD = $(COMMON_LDADD)
......
......@@ -242,6 +242,69 @@ nice_agent_add_stream (
}
static Stream *
_stream_lookup (NiceAgent *agent, guint stream_id)
{
GSList *i;
for (i = agent->streams; i; i = i->next)
{
Stream *s = i->data;
if (s->id == stream_id)
return s;
}
return NULL;
}
/**
* nice_agent_remove_stream:
* @agent: a NiceAgent
* @stream_id: the ID of the stream to remove
**/
void
nice_agent_remove_stream (
NiceAgent *agent,
guint stream_id)
{
/* note that streams/candidates can be in use by other threads */
Stream *stream;
stream = _stream_lookup (agent, stream_id);
if (!stream)
return;
/* remove candidates */
{
GSList *i;
GSList *candidates = agent->local_candidates;
for (i = agent->local_candidates; i; i = i->next)
{
NiceCandidate *candidate = i->data;
if (candidate->stream_id == stream_id)
{
candidates = g_slist_remove (candidates, candidate);
nice_candidate_free (candidate);
}
}
agent->local_candidates = candidates;
}
/* remove stream */
stream_free (stream);
agent->streams = g_slist_remove (agent->streams, stream);
}
/**
* nice_agent_add_local_address:
* @agent: A NiceAgent
......@@ -344,23 +407,6 @@ _local_candidate_lookup_by_fd (NiceAgent *agent, guint fd)
}
static Stream *
_stream_lookup (NiceAgent *agent, guint stream_id)
{
GSList *i;
for (i = agent->streams; i; i = i->next)
{
Stream *s = i->data;
if (s->id == stream_id)
return s;
}
return NULL;
}
static void
_handle_stun_binding_request (
NiceAgent *agent,
......
......@@ -46,6 +46,11 @@ nice_agent_add_stream (
NiceAgentRecvFunc recv_func,
gpointer handle_recv_data);
void
nice_agent_remove_stream (
NiceAgent *agent,
guint stream_id);
void
nice_agent_free (NiceAgent *agent);
......
#include "agent.h"
#include "udp-fake.h"
void
handle_recv (
......@@ -17,11 +18,32 @@ int
main (void)
{
NiceAgent *agent;
NiceAddress addr = {0,};
NiceUDPSocketFactory factory;
nice_udp_fake_socket_factory_init (&factory);
if (!nice_address_set_ipv4_from_string (&addr, "127.0.0.1"))
g_assert_not_reached ();
agent = nice_agent_new (&factory);
nice_agent_add_local_address (agent, &addr);
agent = nice_agent_new (NULL);
g_assert (nice_agent_add_stream (agent, handle_recv, NULL) == 1);
g_assert (nice_agent_add_stream (agent, handle_recv, NULL) == 2);
g_assert (nice_agent_add_stream (agent, handle_recv, NULL) == 3);
g_assert (NULL != agent->streams);
g_assert (NULL != agent->local_candidates);
nice_agent_remove_stream (agent, 1);
nice_agent_remove_stream (agent, 2);
nice_agent_remove_stream (agent, 3);
g_assert (NULL == agent->streams);
/* check no local candidates were left behind when streams were removed*/
g_assert (NULL == agent->local_candidates);
nice_agent_free (agent);
return 0;
......
......@@ -14,6 +14,7 @@ T nice_agent_get_local_candidates
T nice_agent_new
T nice_agent_poll_read
T nice_agent_recv
T nice_agent_remove_stream
T nice_agent_send
T nice_candidate_free
T nice_candidate_ice_priority
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment