summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYouness Alaoui <youness.alaoui@collabora.co.uk>2012-02-08 22:46:07 -0500
committerYouness Alaoui <youness.alaoui@collabora.co.uk>2012-02-08 22:47:18 -0500
commit6449dabb959c8e713c76ecf0c5eac4609c311ca2 (patch)
treed9bb67d5cd8c246427ce3b63dc640fc02c0fd86a
parent85229f996215000a3dc690700cdf015a4c0a7e77 (diff)
parent50e8cf8468f5455c57e175ff54ad90ff14474832 (diff)
Merge branch 'master' of ssh://dhansak/srv/git.collabora.co.uk/git/libnice
Conflicts: configure.ac
-rw-r--r--agent/agent.c23
-rw-r--r--agent/component.c5
-rw-r--r--agent/discovery.c2
-rw-r--r--socket/pseudossl.c2
-rw-r--r--socket/pseudossl.h3
-rw-r--r--socket/tcp-bsd.c9
-rw-r--r--socket/tcp-bsd.h3
-rw-r--r--socket/tcp-turn.c2
-rw-r--r--socket/tcp-turn.h2
-rw-r--r--socket/turn.c32
-rw-r--r--socket/turn.h3
11 files changed, 56 insertions, 30 deletions
diff --git a/agent/agent.c b/agent/agent.c
index 49b2320..04cc4fc 100644
--- a/agent/agent.c
+++ b/agent/agent.c
@@ -1409,7 +1409,7 @@ priv_add_new_candidate_discovery_turn (NiceAgent *agent,
agent->proxy_ip != NULL &&
nice_address_set_from_string (&proxy_server, agent->proxy_ip)) {
nice_address_set_port (&proxy_server, agent->proxy_port);
- socket = nice_tcp_bsd_socket_new (agent, component->ctx, &proxy_server);
+ socket = nice_tcp_bsd_socket_new (agent->main_context, &proxy_server);
if (socket) {
_priv_set_socket_tos (agent, socket, stream->tos);
@@ -1427,14 +1427,14 @@ priv_add_new_candidate_discovery_turn (NiceAgent *agent,
}
if (socket == NULL) {
- socket = nice_tcp_bsd_socket_new (agent, component->ctx, &turn->server);
+ socket = nice_tcp_bsd_socket_new (agent->main_context, &turn->server);
_priv_set_socket_tos (agent, socket, stream->tos);
}
if (turn->type == NICE_RELAY_TYPE_TURN_TLS &&
agent->compatibility == NICE_COMPATIBILITY_GOOGLE) {
- socket = nice_pseudossl_socket_new (agent, socket);
+ socket = nice_pseudossl_socket_new (socket);
}
- cdisco->nicesock = nice_tcp_turn_socket_new (agent, socket,
+ cdisco->nicesock = nice_tcp_turn_socket_new (socket,
agent_to_turn_socket_compatibility (agent));
agent_attach_stream_component_socket (agent, stream,
@@ -2752,10 +2752,18 @@ nice_agent_attach_recv (
ret = TRUE;
+ component->g_source_io_cb = NULL;
+ component->data = NULL;
+ if (component->ctx)
+ g_main_context_unref (component->ctx);
+ component->ctx = NULL;
+
if (func) {
component->g_source_io_cb = func;
component->data = data;
component->ctx = ctx;
+ if (ctx)
+ g_main_context_ref (ctx);
priv_attach_stream_component (agent, stream, component);
@@ -2768,13 +2776,8 @@ nice_agent_attach_recv (
if (component->tcp && component->tcp_data && component->tcp_readable)
pseudo_tcp_socket_readable (component->tcp, component->tcp_data);
- } else {
- component->g_source_io_cb = NULL;
- component->data = NULL;
- component->ctx = NULL;
}
-
done:
agent_unlock();
return ret;
@@ -2834,7 +2837,7 @@ GSource* agent_timeout_add_with_context (NiceAgent *agent, guint interval,
{
GSource *source;
- g_return_val_if_fail (function != NULL, 0);
+ g_return_val_if_fail (function != NULL, NULL);
source = g_timeout_source_new (interval);
diff --git a/agent/component.c b/agent/component.c
index 0c45976..b612154 100644
--- a/agent/component.c
+++ b/agent/component.c
@@ -140,6 +140,11 @@ component_free (Component *cmp)
cmp->tcp_data = NULL;
}
+ if (cmp->ctx != NULL) {
+ g_main_context_unref (cmp->ctx);
+ cmp->ctx = NULL;
+ }
+
g_slice_free (Component, cmp);
}
diff --git a/agent/discovery.c b/agent/discovery.c
index 447f193..eb12dea 100644
--- a/agent/discovery.c
+++ b/agent/discovery.c
@@ -600,7 +600,7 @@ discovery_add_relay_candidate (
candidate->turn = turn;
/* step: link to the base candidate+socket */
- relay_socket = nice_turn_socket_new (agent, address,
+ relay_socket = nice_turn_socket_new (agent->main_context, address,
base_socket, &turn->server,
turn->username, turn->password,
agent_to_turn_socket_compatibility (agent));
diff --git a/socket/pseudossl.c b/socket/pseudossl.c
index f3cf3e1..9107c80 100644
--- a/socket/pseudossl.c
+++ b/socket/pseudossl.c
@@ -101,7 +101,7 @@ static void free_to_be_sent (struct to_be_sent *tbs);
NiceSocket *
-nice_pseudossl_socket_new (NiceAgent *agent, NiceSocket *base_socket)
+nice_pseudossl_socket_new (NiceSocket *base_socket)
{
PseudoSSLPriv *priv;
NiceSocket *sock = g_slice_new0 (NiceSocket);
diff --git a/socket/pseudossl.h b/socket/pseudossl.h
index a9847b1..38ea309 100644
--- a/socket/pseudossl.h
+++ b/socket/pseudossl.h
@@ -38,13 +38,12 @@
#define _PSEUDOSSL_H
#include "socket.h"
-#include "agent.h"
G_BEGIN_DECLS
NiceSocket *
-nice_pseudossl_socket_new (NiceAgent *agent, NiceSocket *base_socket);
+nice_pseudossl_socket_new (NiceSocket *base_socket);
G_END_DECLS
diff --git a/socket/tcp-bsd.c b/socket/tcp-bsd.c
index 255a234..ac90eaa 100644
--- a/socket/tcp-bsd.c
+++ b/socket/tcp-bsd.c
@@ -54,7 +54,6 @@
#endif
typedef struct {
- NiceAgent *agent;
NiceAddress server_addr;
GQueue send_queue;
GMainContext *context;
@@ -86,7 +85,7 @@ static gboolean socket_send_more (GIOChannel *source, GIOCondition condition,
gpointer data);
NiceSocket *
-nice_tcp_bsd_socket_new (NiceAgent *agent, GMainContext *ctx, NiceAddress *addr)
+nice_tcp_bsd_socket_new (GMainContext *ctx, NiceAddress *addr)
{
int sockfd = -1;
int ret;
@@ -163,8 +162,7 @@ nice_tcp_bsd_socket_new (NiceAgent *agent, GMainContext *ctx, NiceAddress *addr)
sock->priv = priv = g_slice_new0 (TcpPriv);
- priv->agent = agent;
- priv->context = ctx;
+ priv->context = g_main_context_ref (ctx);
priv->server_addr = *addr;
priv->error = FALSE;
@@ -197,6 +195,9 @@ socket_close (NiceSocket *sock)
g_queue_foreach (&priv->send_queue, (GFunc) free_to_be_sent, NULL);
g_queue_clear (&priv->send_queue);
+ if (priv->context)
+ g_main_context_unref (priv->context);
+
g_slice_free(TcpPriv, sock->priv);
}
diff --git a/socket/tcp-bsd.h b/socket/tcp-bsd.h
index f50389b..e3a0593 100644
--- a/socket/tcp-bsd.h
+++ b/socket/tcp-bsd.h
@@ -38,13 +38,12 @@
#define _TCP_BSD_H
#include "socket.h"
-#include "agent.h"
G_BEGIN_DECLS
NiceSocket *
-nice_tcp_bsd_socket_new (NiceAgent *agent, GMainContext *ctx, NiceAddress *addr);
+nice_tcp_bsd_socket_new (GMainContext *ctx, NiceAddress *addr);
G_END_DECLS
diff --git a/socket/tcp-turn.c b/socket/tcp-turn.c
index 0f527e8..3a4f12a 100644
--- a/socket/tcp-turn.c
+++ b/socket/tcp-turn.c
@@ -70,7 +70,7 @@ static gboolean socket_send (NiceSocket *sock, const NiceAddress *to,
static gboolean socket_is_reliable (NiceSocket *sock);
NiceSocket *
-nice_tcp_turn_socket_new (NiceAgent *agent, NiceSocket *base_socket,
+nice_tcp_turn_socket_new (NiceSocket *base_socket,
NiceTurnSocketCompatibility compatibility)
{
TurnTcpPriv *priv;
diff --git a/socket/tcp-turn.h b/socket/tcp-turn.h
index 4b65de4..a6ccf1c 100644
--- a/socket/tcp-turn.h
+++ b/socket/tcp-turn.h
@@ -44,7 +44,7 @@ G_BEGIN_DECLS
NiceSocket *
-nice_tcp_turn_socket_new (NiceAgent *agent, NiceSocket *base_socket,
+nice_tcp_turn_socket_new (NiceSocket *base_socket,
NiceTurnSocketCompatibility compatibility);
diff --git a/socket/turn.c b/socket/turn.c
index 4d6fad8..55a0aec 100644
--- a/socket/turn.c
+++ b/socket/turn.c
@@ -71,7 +71,7 @@ typedef struct {
} ChannelBinding;
typedef struct {
- NiceAgent *nice;
+ GMainContext *ctx;
StunAgent agent;
GList *channels;
GList *pending_bindings;
@@ -161,7 +161,7 @@ priv_send_data_queue_destroy (gpointer data)
}
NiceSocket *
-nice_turn_socket_new (NiceAgent *agent, NiceAddress *addr,
+nice_turn_socket_new (GMainContext *ctx, NiceAddress *addr,
NiceSocket *base_socket, NiceAddress *server_addr,
gchar *username, gchar *password,
NiceTurnSocketCompatibility compatibility)
@@ -198,10 +198,11 @@ nice_turn_socket_new (NiceAgent *agent, NiceAddress *addr,
STUN_AGENT_USAGE_NO_ALIGNED_ATTRIBUTES);
}
- priv->nice = agent;
priv->channels = NULL;
priv->current_binding = NULL;
priv->base_socket = base_socket;
+ if (ctx)
+ priv->ctx = g_main_context_ref (ctx);
if (compatibility == NICE_TURN_SOCKET_COMPATIBILITY_MSN ||
compatibility == NICE_TURN_SOCKET_COMPATIBILITY_OC2007) {
@@ -291,6 +292,9 @@ socket_close (NiceSocket *sock)
if (priv->permission_timeout_source)
g_source_remove (priv->permission_timeout_source);
+ if (priv->ctx)
+ g_main_context_unref (priv->ctx);
+
g_free (priv->current_binding);
g_free (priv->current_binding_msg);
g_free (priv->current_create_permission_msg);
@@ -321,6 +325,22 @@ socket_recv (NiceSocket *sock, NiceAddress *from, guint len, gchar *buf)
return recv_len;
}
+static GSource *
+priv_timeout_add_with_context (TurnPriv *priv, guint interval,
+ GSourceFunc function, gpointer data)
+{
+ GSource *source;
+
+ g_return_val_if_fail (function != NULL, NULL);
+
+ source = g_timeout_source_new (interval);
+
+ g_source_set_callback (source, function, data, NULL);
+ g_source_attach (source, priv->ctx);
+
+ return source;
+}
+
static StunMessageReturn
stun_message_append_ms_connection_id(StunMessage *msg,
uint8_t *ms_connection_id, uint32_t ms_sequence_num)
@@ -557,7 +577,7 @@ socket_send (NiceSocket *sock, const NiceAddress *to,
req->priv = priv;
stun_message_id (&msg, req->id);
- req->source = agent_timeout_add_with_context (priv->nice,
+ req->source = priv_timeout_add_with_context (priv,
STUN_END_TIMEOUT, priv_forget_send_request, req);
g_queue_push_tail (priv->send_requests, req);
}
@@ -1275,7 +1295,7 @@ priv_schedule_tick (TurnPriv *priv)
guint timeout = stun_timer_remainder (&priv->current_binding_msg->timer);
if (timeout > 0) {
priv->tick_source_channel_bind =
- agent_timeout_add_with_context (priv->nice, timeout,
+ priv_timeout_add_with_context (priv, timeout,
priv_retransmissions_tick, priv);
} else {
priv_retransmissions_tick_unlocked (priv);
@@ -1288,7 +1308,7 @@ priv_schedule_tick (TurnPriv *priv)
if (timeout > 0) {
priv->tick_source_create_permission =
- agent_timeout_add_with_context (priv->nice,
+ priv_timeout_add_with_context (priv,
timeout,
priv_retransmissions_create_permission_tick,
priv);
diff --git a/socket/turn.h b/socket/turn.h
index 1b4df7b..fee8108 100644
--- a/socket/turn.h
+++ b/socket/turn.h
@@ -47,7 +47,6 @@ typedef enum {
} NiceTurnSocketCompatibility;
#include "socket.h"
-#include "agent.h"
#include "stun/stunmessage.h"
@@ -62,7 +61,7 @@ gboolean
nice_turn_socket_set_peer (NiceSocket *sock, NiceAddress *peer);
NiceSocket *
-nice_turn_socket_new (NiceAgent *agent, NiceAddress *addr,
+nice_turn_socket_new (GMainContext *ctx, NiceAddress *addr,
NiceSocket *base_socket, NiceAddress *server_addr,
gchar *username, gchar *password, NiceTurnSocketCompatibility compatibility);