Commit 878ca74d authored by Dafydd Harries's avatar Dafydd Harries

give nice_agent_poll_read a callback to call, rather than using the stream's

darcs-hash:20070209184232-c9803-99a48d5c2e787f3aca466fda3b05a6c272f89fe0.gz
parent 114187b1
...@@ -701,44 +701,6 @@ _nice_agent_recv ( ...@@ -701,44 +701,6 @@ _nice_agent_recv (
} }
static void
_nice_agent_recv_to_cb (
NiceAgent *agent,
Stream *stream,
NiceCandidate *candidate)
{
gchar buf[1024];
guint len;
len = _nice_agent_recv (agent, stream, candidate, 1024, buf);
if (len)
{
/* XXX: should a NULL data handler be permitted? */
g_assert (stream->handle_recv != NULL);
stream->handle_recv (agent, stream->id, candidate->component_id, len,
buf, stream->handle_recv_data);
}
}
static void
_nice_agent_candidate_recv (
NiceAgent *agent,
NiceCandidate *candidate)
{
Stream *stream;
stream = _stream_lookup (agent, candidate->stream_id);
if (stream == NULL)
/* odd: a candidate that doesn't belong to a stream */
return;
_nice_agent_recv_to_cb (agent, stream, candidate);
}
/** /**
* nice_agent_recv: * nice_agent_recv:
* @agent: a NiceAgent * @agent: a NiceAgent
...@@ -827,7 +789,11 @@ nice_agent_recv ( ...@@ -827,7 +789,11 @@ nice_agent_recv (
* Returns: A list of file descriptors from @other_fds that are readable * Returns: A list of file descriptors from @other_fds that are readable
**/ **/
GSList * GSList *
nice_agent_poll_read (NiceAgent *agent, GSList *other_fds) nice_agent_poll_read (
NiceAgent *agent,
GSList *other_fds,
NiceAgentRecvFunc func,
gpointer data)
{ {
fd_set fds; fd_set fds;
guint max_fd = 0; guint max_fd = 0;
...@@ -875,7 +841,22 @@ nice_agent_poll_read (NiceAgent *agent, GSList *other_fds) ...@@ -875,7 +841,22 @@ nice_agent_poll_read (NiceAgent *agent, GSList *other_fds)
NiceCandidate *candidate = i->data; NiceCandidate *candidate = i->data;
if (candidate->sock.fileno == j) if (candidate->sock.fileno == j)
_nice_agent_candidate_recv (agent, candidate); {
Stream *stream;
gchar buf[1024];
guint len;
stream = _stream_lookup (agent, candidate->stream_id);
if (stream == NULL)
break;
len = _nice_agent_recv (agent, stream, candidate, 1024, buf);
if (len && func != NULL)
func (agent, stream->id, candidate->component_id, len, buf,
stream->handle_recv_data);
}
} }
} }
......
...@@ -75,7 +75,9 @@ nice_agent_recv ( ...@@ -75,7 +75,9 @@ nice_agent_recv (
GSList * GSList *
nice_agent_poll_read ( nice_agent_poll_read (
NiceAgent *agent, NiceAgent *agent,
GSList *other_fds); GSList *other_fds,
NiceAgentRecvFunc func,
gpointer data);
void void
nice_agent_send ( nice_agent_send (
......
...@@ -60,7 +60,7 @@ main (void) ...@@ -60,7 +60,7 @@ main (void)
/* poll */ /* poll */
readable = nice_agent_poll_read (agent, fds); readable = nice_agent_poll_read (agent, fds, NULL, NULL);
g_assert (g_slist_length (readable) == 1); g_assert (g_slist_length (readable) == 1);
g_assert (GPOINTER_TO_UINT (readable->data) == pipe_fds[0]); g_assert (GPOINTER_TO_UINT (readable->data) == pipe_fds[0]);
g_slist_free (readable); g_slist_free (readable);
...@@ -79,7 +79,7 @@ main (void) ...@@ -79,7 +79,7 @@ main (void)
/* poll again */ /* poll again */
readable = nice_agent_poll_read (agent, fds); readable = nice_agent_poll_read (agent, fds, handle_recv, NULL);
g_assert (cb_called == TRUE); g_assert (cb_called == TRUE);
g_assert (readable == NULL); g_assert (readable == NULL);
......
...@@ -4,8 +4,6 @@ ...@@ -4,8 +4,6 @@
#include "udp-fake.h" #include "udp-fake.h"
#include "agent.h" #include "agent.h"
static gboolean cb_called = FALSE;
void void
handle_recv ( handle_recv (
NiceAgent *agent, NiceAgent *agent,
...@@ -15,12 +13,7 @@ handle_recv ( ...@@ -15,12 +13,7 @@ handle_recv (
gchar *buf, gchar *buf,
gpointer data) gpointer data)
{ {
g_assert (cb_called == FALSE); g_assert_not_reached ();
g_assert (stream_id == 1);
g_assert (component_id == 1);
g_assert (len == 7);
g_assert (0 == strncmp (buf, "\x80lalala", 7));
cb_called = TRUE;
} }
int int
......
...@@ -43,7 +43,7 @@ send_connectivity_check ( ...@@ -43,7 +43,7 @@ send_connectivity_check (
stun_message_free (msg); stun_message_free (msg);
} }
nice_agent_poll_read (agent, NULL); nice_agent_poll_read (agent, NULL, NULL, NULL);
{ {
StunMessage *msg; StunMessage *msg;
......
...@@ -48,7 +48,7 @@ test_stun_no_password ( ...@@ -48,7 +48,7 @@ test_stun_no_password (
} }
/* tell the agent there's a packet waiting */ /* tell the agent there's a packet waiting */
nice_agent_poll_read (agent, NULL); nice_agent_poll_read (agent, NULL, NULL, NULL);
/* error response should have been sent */ /* error response should have been sent */
len = nice_udp_fake_socket_pop_send (sock, &to, len = nice_udp_fake_socket_pop_send (sock, &to,
...@@ -104,7 +104,7 @@ test_stun_invalid_password ( ...@@ -104,7 +104,7 @@ test_stun_invalid_password (
} }
/* tell the agent there's a packet waiting */ /* tell the agent there's a packet waiting */
nice_agent_poll_read (agent, NULL); nice_agent_poll_read (agent, NULL, NULL, NULL);
/* error should have been sent */ /* error should have been sent */
len = nice_udp_fake_socket_pop_send (sock, &to, len = nice_udp_fake_socket_pop_send (sock, &to,
...@@ -182,7 +182,7 @@ test_stun_valid_password ( ...@@ -182,7 +182,7 @@ test_stun_valid_password (
g_free (username); g_free (username);
/* tell the agent there's a packet waiting */ /* tell the agent there's a packet waiting */
nice_agent_poll_read (agent, NULL); nice_agent_poll_read (agent, NULL, NULL, NULL);
/* compare sent packet to expected */ /* compare sent packet to expected */
len = nice_udp_fake_socket_pop_send (sock, &to, len = nice_udp_fake_socket_pop_send (sock, &to,
......
...@@ -113,7 +113,7 @@ handle_connection (guint fileno, const struct sockaddr_in *sin, gpointer data) ...@@ -113,7 +113,7 @@ handle_connection (guint fileno, const struct sockaddr_in *sin, gpointer data)
GSList *out_fds; GSList *out_fds;
GSList *i; GSList *i;
out_fds = nice_agent_poll_read (agent, in_fds); out_fds = nice_agent_poll_read (agent, in_fds, handle_recv, NULL);
for (i = out_fds; i; i = i->next) for (i = out_fds; i; i = i->next)
if (GPOINTER_TO_UINT (i->data) == fileno) if (GPOINTER_TO_UINT (i->data) == fileno)
......
...@@ -103,7 +103,7 @@ accept_connection ( ...@@ -103,7 +103,7 @@ accept_connection (
gchar **bits; gchar **bits;
NiceAddress addr; NiceAddress addr;
if (nice_agent_poll_read (agent, fds) == NULL) if (nice_agent_poll_read (agent, fds, recv_cb, NULL) == NULL)
continue; continue;
len = nice_udp_socket_recv (sock, &recv_addr, 1024, buf); len = nice_udp_socket_recv (sock, &recv_addr, 1024, buf);
......
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