Commit fa5fb7ae authored by Youness Alaoui's avatar Youness Alaoui

Remove the nice_agent_recv/recv_sock/poll_read APIs because they are useless...

Remove the nice_agent_recv/recv_sock/poll_read APIs because they are useless now. We want to enforce using the gmainloop as it is necessary for a lot of other stuff
parent 286b8120
......@@ -68,9 +68,7 @@ libagent_la_DEPENDENCIES = \
check_PROGRAMS = \
test \
test-add-remove-stream \
test-recv \
test-priority \
test-poll \
test-mainloop \
test-fullmode \
test-restart \
......@@ -86,12 +84,8 @@ test_LDADD = $(COMMON_LDADD)
test_add_remove_stream_LDADD = $(COMMON_LDADD)
test_recv_LDADD = $(COMMON_LDADD)
test_priority_LDADD = $(COMMON_LDADD)
test_poll_LDADD = $(COMMON_LDADD)
test_mainloop_LDADD = $(COMMON_LDADD)
test_fullmode_LDADD = $(COMMON_LDADD)
......
......@@ -1396,238 +1396,6 @@ _nice_agent_recv (
return len;
}
/**
* nice_agent_recv:
* @agent: a NiceAgent
* @stream_id: the ID of the stream to recieve data from
* @component_id: the ID of the component to receive data from
* @buf_len: the size of @buf
* @buf: the buffer to read data into
*
* Receive data on a particular component.
*
* Returns: the amount of data read into @buf
**/
NICEAPI_EXPORT guint
nice_agent_recv (
NiceAgent *agent,
guint stream_id,
guint component_id,
guint buf_len,
gchar *buf)
{
gint len = 0;
fd_set fds;
guint max_fd = 0;
gint num_readable;
GSList *i;
Stream *stream;
Component *component;
guint ret = 0;
g_static_rec_mutex_lock (&agent->mutex);
if (!agent_find_component (agent, stream_id, component_id, &stream, &component)) {
goto done;
}
FD_ZERO (&fds);
for (i = component->sockets; i; i = i->next)
{
NiceSocket *sockptr = i->data;
FD_SET (sockptr->fileno, &fds);
max_fd = MAX (sockptr->fileno, max_fd);
}
/* Loop on candidate sockets until we find one that has non-STUN data
* waiting on it.
*/
for (;;)
{
num_readable = select (max_fd + 1, &fds, NULL, NULL, NULL);
g_assert (num_readable >= 0);
if (num_readable > 0)
{
guint j;
for (j = 0; j <= max_fd; j++)
if (FD_ISSET (j, &fds))
{
NiceSocket *socket;
socket = component_find_socket_by_fd (component, j);
g_assert (socket);
len = _nice_agent_recv (agent, stream, component, socket,
buf_len, buf);
if (len >= 0) {
ret = len;
goto done;
}
}
}
}
/* note: commented out to avoid compiler warnings
*
* g_assert_not_reached (); */
done:
g_static_rec_mutex_unlock (&agent->mutex);
return ret;
}
NICEAPI_EXPORT guint
nice_agent_recv_sock (
NiceAgent *agent,
guint stream_id,
guint component_id,
guint sock,
guint buf_len,
gchar *buf)
{
NiceSocket *socket;
Stream *stream;
Component *component;
guint ret = 0;
g_static_rec_mutex_lock (&agent->mutex);
if (!agent_find_component (agent, stream_id, component_id, &stream, &component)) {
goto done;
}
socket = component_find_socket_by_fd (component, sock);
g_assert (socket);
ret = _nice_agent_recv (agent, stream, component,
socket, buf_len, buf);
done:
g_static_rec_mutex_unlock (&agent->mutex);
return ret;
}
/**
* nice_agent_poll_read:
* @agent: A NiceAgent
* @other_fds: A GSList of other file descriptors to poll
*
* Polls the agent's sockets until at least one of them is readable, and
* additionally if @other_fds is not NULL, polls those for readability too.
* @other_fds should contain the file descriptors directly, i.e. using
* GUINT_TO_POINTER.
*
* Returns: A list of file descriptors from @other_fds that are readable
**/
NICEAPI_EXPORT GSList *
nice_agent_poll_read (
NiceAgent *agent,
GSList *other_fds,
NiceAgentRecvFunc func,
gpointer data)
{
fd_set fds;
guint max_fd = 0;
gint num_readable;
GSList *ret = NULL;
GSList *i;
guint j;
g_static_rec_mutex_lock (&agent->mutex);
FD_ZERO (&fds);
for (i = agent->streams; i; i = i->next)
{
GSList *j, *k;
Stream *stream = i->data;
for (k = stream->components; k; k = k->next)
{
Component *component = k->data;
for (j = component->sockets; j; j = j->next)
{
NiceSocket *sockptr = j->data;
FD_SET (sockptr->fileno, &fds);
max_fd = MAX (sockptr->fileno, max_fd);
}
}
}
for (i = other_fds; i; i = i->next)
{
guint fileno;
fileno = GPOINTER_TO_UINT (i->data);
FD_SET (fileno, &fds);
max_fd = MAX (fileno, max_fd);
}
num_readable = select (max_fd + 1, &fds, NULL, NULL, NULL);
if (num_readable < 1) {
/* none readable, or error */
goto done;
}
for (j = 0; j <= max_fd; j++)
if (FD_ISSET (j, &fds))
{
if (g_slist_find (other_fds, GUINT_TO_POINTER (j))) {
GSList *modified_list = g_slist_append (ret, GUINT_TO_POINTER (j));
if (modified_list == NULL) {
g_slist_free (ret);
goto done;
}
ret = modified_list;
}
else
{
NiceSocket *socket = NULL;
Stream *stream = NULL;
Component *component = NULL;
gchar buf[MAX_BUFFER_SIZE];
guint len;
for (i = agent->streams; i; i = i->next)
{
Stream *s = i->data;
Component *c = stream_find_component_by_fd (s, j);
socket = component_find_socket_by_fd (c, j);
if (socket != NULL) {
stream = s;
component = c;
break;
}
}
if (socket == NULL || stream == NULL || component == NULL)
break;
len = _nice_agent_recv (agent, stream, component,
socket, MAX_BUFFER_SIZE, buf);
if (len && func != NULL)
func (agent, stream->id, component->id, len, buf,
data);
}
}
done:
g_static_rec_mutex_unlock (&agent->mutex);
return ret;
}
/**
* Sends a data payload over a stream component.
*
......
......@@ -184,30 +184,6 @@ nice_agent_set_remote_candidates (
guint component_id,
const GSList *candidates);
guint
nice_agent_recv (
NiceAgent *agent,
guint stream_id,
guint component_id,
guint buf_len,
gchar *buf);
guint
nice_agent_recv_sock (
NiceAgent *agent,
guint stream_id,
guint component_id,
guint sock,
guint buf_len,
gchar *buf);
GSList *
nice_agent_poll_read (
NiceAgent *agent,
GSList *other_fds,
NiceAgentRecvFunc func,
gpointer data);
gint
nice_agent_send (
NiceAgent *agent,
......
......@@ -43,8 +43,8 @@
#include "agent.h"
#define USE_TURN 1
#define USE_LOOPBACK 0
#define USE_TURN 0
#define USE_LOOPBACK 1
#if USE_LOOPBACK
#define USE_TURN_SERVER_ORG 1
......
/*
* This file is part of the Nice GLib ICE library.
*
* (C) 2006, 2007 Collabora Ltd.
* Contact: Dafydd Harries
* (C) 2006, 2007 Nokia Corporation. All rights reserved.
* Contact: Kai Vehmanen
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is the Nice GLib ICE library.
*
* The Initial Developers of the Original Code are Collabora Ltd and Nokia
* Corporation. All Rights Reserved.
*
* Contributors:
* Dafydd Harries, Collabora Ltd.
* Kai Vehmanen, Nokia
*
* Alternatively, the contents of this file may be used under the terms of the
* the GNU Lesser General Public License Version 2.1 (the "LGPL"), in which
* case the provisions of LGPL are applicable instead of those above. If you
* wish to allow use of your version of this file only under the terms of the
* LGPL and not to allow others to use your version of this file under the
* MPL, indicate your decision by deleting the provisions above and replace
* them with the notice and other provisions required by the LGPL. If you do
* not delete the provisions above, a recipient may use your version of this
* file under either the MPL or the LGPL.
*/
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <string.h>
#include <unistd.h>
#include <nice/nice.h>
static gboolean cb_called = FALSE;
static void
handle_recv (
NiceAgent *agent,
guint stream_id,
guint component_id,
guint len,
gchar *buf,
gpointer data)
{
g_assert (agent != NULL);
g_assert (cb_called == FALSE);
g_assert (stream_id == 1);
g_assert (component_id == 1);
g_assert (len == 7);
g_assert (0 == strncmp (buf, "\x80lalala", 7));
g_assert (GPOINTER_TO_UINT (data) == 42);
cb_called = TRUE;
}
int
main (void)
{
NiceAgent *agent;
NiceAddress addr;
NiceSocket *sock;
gint pipe_fds[2];
GSList *fds = NULL;
GSList *readable;
ssize_t w;
guint stream_id;
nice_address_init (&addr);
g_type_init ();
g_thread_init (NULL);
/* set up agent */
if (!nice_address_set_from_string (&addr, "127.0.0.1"))
g_assert_not_reached ();
agent = nice_agent_new (NULL, NICE_COMPATIBILITY_DRAFT19);
nice_agent_add_local_address (agent, &addr);
stream_id = nice_agent_add_stream (agent, 1);
nice_agent_gather_candidates (agent, stream_id);
{
GSList *candidates;
NiceCandidate *candidate;
candidates = nice_agent_get_local_candidates (agent, stream_id, 1);
candidate = candidates->data;
sock = candidate->sockptr;
addr = candidate->addr;
g_slist_free (candidates);
}
/* set up pipe and fd list */
if (pipe (pipe_fds) != 0)
g_assert_not_reached ();
w = write (pipe_fds[1], "hello", 5);
g_assert (w == 5);
fds = g_slist_append (fds, GUINT_TO_POINTER (pipe_fds[0]));
/* poll */
readable = nice_agent_poll_read (agent, fds, NULL, NULL);
g_assert (g_slist_length (readable) == 1);
g_assert (GPOINTER_TO_UINT (readable->data) == (guint) pipe_fds[0]);
g_slist_free (readable);
g_assert (cb_called == FALSE);
{
gchar buf[1024];
g_assert (5 == read (pipe_fds[0], buf, 1024));
g_assert (0 == strncmp (buf, "hello", 5));
}
/* send fake data */
nice_socket_send (sock, &addr, 7, "\x80lalala");
/* poll again */
readable = nice_agent_poll_read (agent, fds, handle_recv,
GUINT_TO_POINTER (42));
g_assert (cb_called == TRUE);
g_assert (readable == NULL);
/* clean up */
g_slist_free (fds);
g_object_unref (agent);
return 0;
}
/*
* This file is part of the Nice GLib ICE library.
*
* (C) 2006, 2007 Collabora Ltd.
* Contact: Dafydd Harries
* (C) 2006, 2007 Nokia Corporation. All rights reserved.
* Contact: Kai Vehmanen
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is the Nice GLib ICE library.
*
* The Initial Developers of the Original Code are Collabora Ltd and Nokia
* Corporation. All Rights Reserved.
*
* Contributors:
* Dafydd Harries, Collabora Ltd.
* Kai Vehmanen, Nokia
*
* Alternatively, the contents of this file may be used under the terms of the
* the GNU Lesser General Public License Version 2.1 (the "LGPL"), in which
* case the provisions of LGPL are applicable instead of those above. If you
* wish to allow use of your version of this file only under the terms of the
* LGPL and not to allow others to use your version of this file under the
* MPL, indicate your decision by deleting the provisions above and replace
* them with the notice and other provisions required by the LGPL. If you do
* not delete the provisions above, a recipient may use your version of this
* file under either the MPL or the LGPL.
*/
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <string.h>
#include "agent.h"
int
main (void)
{
NiceAgent *agent;
NiceAddress addr;
guint stream_id;
nice_address_init (&addr);
g_type_init ();
g_thread_init (NULL);
/* set up agent */
agent = nice_agent_new (NULL, NICE_COMPATIBILITY_DRAFT19);
g_assert (nice_address_set_from_string (&addr, "127.0.0.1"));
nice_agent_add_local_address (agent, &addr);
stream_id = nice_agent_add_stream (agent, 1);
nice_agent_gather_candidates (agent, stream_id);
/* recieve an RTP packet */
{
NiceCandidate *candidate;
guint len;
gchar buf[1024];
GSList *candidates;
candidates = nice_agent_get_local_candidates (agent, stream_id, 1);
candidate = candidates->data;
g_slist_free (candidates);
nice_socket_send (candidate->sockptr, &candidate->addr, 7, "\x80lalala");
len = nice_agent_recv (agent, stream_id,
candidate->component_id, 1024, buf);
g_assert (len == 7);
g_assert (0 == strncmp (buf, "\x80lalala", 7));
}
/* clean up */
g_object_unref (agent);
return 0;
}
......@@ -22,9 +22,6 @@ nice_agent_get_local_credentials
nice_agent_get_remote_candidates
nice_agent_get_type
nice_agent_new
nice_agent_poll_read
nice_agent_recv
nice_agent_recv_sock
nice_agent_remove_stream
nice_agent_restart
nice_agent_send
......
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