Commit b8d2b05c authored by Dafydd Harries's avatar Dafydd Harries

ice-test-server: convert to using nice_agent_poll_read

darcs-hash:20070203101159-c9803-36d838ab327fbc5a558baf53d3c6f7f8931654f6.gz
parent ffff6674
...@@ -86,11 +86,9 @@ handle_connection (guint fileno, const struct sockaddr_in *sin, gpointer data) ...@@ -86,11 +86,9 @@ handle_connection (guint fileno, const struct sockaddr_in *sin, gpointer data)
NiceAgent *agent; NiceAgent *agent;
NiceUDPSocketFactory factory; NiceUDPSocketFactory factory;
NiceUDPSocket *sock; NiceUDPSocket *sock;
GSList *sockets = NULL;
gchar ip_str[INET_ADDRSTRLEN]; gchar ip_str[INET_ADDRSTRLEN];
fd_set fds;
guint max_fd;
gchar *candidate_str; gchar *candidate_str;
GSList *in_fds = NULL;
inet_ntop (AF_INET, &(sin->sin_addr), ip_str, INET_ADDRSTRLEN); inet_ntop (AF_INET, &(sin->sin_addr), ip_str, INET_ADDRSTRLEN);
g_debug ("got connection from %s:%d", ip_str, ntohs (sin->sin_port)); g_debug ("got connection from %s:%d", ip_str, ntohs (sin->sin_port));
...@@ -100,8 +98,6 @@ handle_connection (guint fileno, const struct sockaddr_in *sin, gpointer data) ...@@ -100,8 +98,6 @@ handle_connection (guint fileno, const struct sockaddr_in *sin, gpointer data)
if (!make_agent ((gchar *) data, &factory, &agent, &sock)) if (!make_agent ((gchar *) data, &factory, &agent, &sock))
return; return;
sockets = g_slist_append (sockets, sock);
/* send first local candidate to remote end */ /* send first local candidate to remote end */
candidate_str = nice_candidate_to_string ( candidate_str = nice_candidate_to_string (
nice_agent_get_local_candidates (agent)->data); nice_agent_get_local_candidates (agent)->data);
...@@ -111,60 +107,33 @@ handle_connection (guint fileno, const struct sockaddr_in *sin, gpointer data) ...@@ -111,60 +107,33 @@ handle_connection (guint fileno, const struct sockaddr_in *sin, gpointer data)
/* event loop */ /* event loop */
FD_ZERO (&fds); in_fds = g_slist_append (in_fds, GUINT_TO_POINTER (fileno));
FD_SET (fileno, &fds);
FD_SET (sock->fileno, &fds);
max_fd = MAX (fileno, sock->fileno) + 1;
g_debug ("fileno = %d", fileno);
for (;;) for (;;)
{ {
fd_set tmp = fds; GSList *out_fds;
guint ret; GSList *i;
guint i;
ret = select (max_fd, &tmp, NULL, NULL, 0); out_fds = nice_agent_poll_read (agent, in_fds);
for (i = 0; i < max_fd; i++) for (i = out_fds; i; i = i->next)
{ if (GPOINTER_TO_UINT (i->data) == fileno)
if (!FD_ISSET (i, &tmp)) {
continue; /* TCP data */
if (i == fileno) g_debug ("got TCP data");
{
/* TCP data */ if (!handle_tcp_read (fileno, agent))
goto END;
g_debug ("got TCP data"); }
if (!handle_tcp_read (fileno, agent)) g_slist_free (out_fds);
goto END;
}
else if (i == sock->fileno)
{
/* UDP data */
/* XXX: candidate number is hardcoded */
nice_agent_recv (agent, 1);
}
}
} }
END: END:
g_debug ("-- connection closed --"); g_debug ("-- connection closed --");
while (sockets != NULL) g_slist_free (in_fds);
{
GSList *tmp;
NiceUDPSocket *sock = sockets->data;
tmp = sockets;
sockets = sockets->next;
g_slist_free_1 (tmp);
nice_udp_socket_close (sock);
g_slice_free (NiceUDPSocket, sock);
}
g_slist_free (sockets);
nice_udp_socket_factory_close (&factory); nice_udp_socket_factory_close (&factory);
nice_agent_free (agent); nice_agent_free (agent);
} }
...@@ -238,4 +207,3 @@ main (int argc, char **argv) ...@@ -238,4 +207,3 @@ main (int argc, char **argv)
return 0; return 0;
} }
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