Commit dfba87d0 authored by Youness Alaoui's avatar Youness Alaoui Committed by Olivier Crête

Add a nice_socket_can_send and nice_socket_set_writable_callback APIs

parent fbd58604
...@@ -92,6 +92,9 @@ static gint socket_send_messages (NiceSocket *sock, const NiceAddress *to, ...@@ -92,6 +92,9 @@ static gint socket_send_messages (NiceSocket *sock, const NiceAddress *to,
static gint socket_send_messages_reliable (NiceSocket *sock, static gint socket_send_messages_reliable (NiceSocket *sock,
const NiceAddress *to, const NiceOutputMessage *messages, guint n_messages); const NiceAddress *to, const NiceOutputMessage *messages, guint n_messages);
static gboolean socket_is_reliable (NiceSocket *sock); static gboolean socket_is_reliable (NiceSocket *sock);
static gboolean socket_can_send (NiceSocket *sock, NiceAddress *addr);
static void socket_set_writable_callback (NiceSocket *sock,
NiceSocketWritableCb callback, gpointer user_data);
NiceSocket * NiceSocket *
nice_http_socket_new (NiceSocket *base_socket, nice_http_socket_new (NiceSocket *base_socket,
...@@ -121,6 +124,8 @@ nice_http_socket_new (NiceSocket *base_socket, ...@@ -121,6 +124,8 @@ nice_http_socket_new (NiceSocket *base_socket,
sock->send_messages_reliable = socket_send_messages_reliable; sock->send_messages_reliable = socket_send_messages_reliable;
sock->recv_messages = socket_recv_messages; sock->recv_messages = socket_recv_messages;
sock->is_reliable = socket_is_reliable; sock->is_reliable = socket_is_reliable;
sock->can_send = socket_can_send;
sock->set_writable_callback = socket_set_writable_callback;
sock->close = socket_close; sock->close = socket_close;
/* Send HTTP CONNECT */ /* Send HTTP CONNECT */
...@@ -611,3 +616,20 @@ socket_is_reliable (NiceSocket *sock) ...@@ -611,3 +616,20 @@ socket_is_reliable (NiceSocket *sock)
return nice_socket_is_reliable (priv->base_socket); return nice_socket_is_reliable (priv->base_socket);
} }
static gboolean
socket_can_send (NiceSocket *sock, NiceAddress *addr)
{
HttpPriv *priv = sock->priv;
return nice_socket_can_send (priv->base_socket, addr);
}
static void
socket_set_writable_callback (NiceSocket *sock,
NiceSocketWritableCb callback, gpointer user_data)
{
HttpPriv *priv = sock->priv;
nice_socket_set_writable_callback (priv->base_socket, callback, user_data);
}
...@@ -113,6 +113,9 @@ static gint socket_send_messages (NiceSocket *sock, const NiceAddress *to, ...@@ -113,6 +113,9 @@ static gint socket_send_messages (NiceSocket *sock, const NiceAddress *to,
static gint socket_send_messages_reliable (NiceSocket *sock, static gint socket_send_messages_reliable (NiceSocket *sock,
const NiceAddress *to, const NiceOutputMessage *messages, guint n_messages); const NiceAddress *to, const NiceOutputMessage *messages, guint n_messages);
static gboolean socket_is_reliable (NiceSocket *sock); static gboolean socket_is_reliable (NiceSocket *sock);
static gboolean socket_can_send (NiceSocket *sock, NiceAddress *addr);
static void socket_set_writable_callback (NiceSocket *sock,
NiceSocketWritableCb callback, gpointer user_data);
NiceSocket * NiceSocket *
nice_pseudossl_socket_new (NiceSocket *base_socket, nice_pseudossl_socket_new (NiceSocket *base_socket,
...@@ -147,6 +150,8 @@ nice_pseudossl_socket_new (NiceSocket *base_socket, ...@@ -147,6 +150,8 @@ nice_pseudossl_socket_new (NiceSocket *base_socket,
sock->send_messages_reliable = socket_send_messages_reliable; sock->send_messages_reliable = socket_send_messages_reliable;
sock->recv_messages = socket_recv_messages; sock->recv_messages = socket_recv_messages;
sock->is_reliable = socket_is_reliable; sock->is_reliable = socket_is_reliable;
sock->can_send = socket_can_send;
sock->set_writable_callback = socket_set_writable_callback;
sock->close = socket_close; sock->close = socket_close;
/* We send 'to' NULL because it will always be to an already connected /* We send 'to' NULL because it will always be to an already connected
...@@ -288,3 +293,20 @@ socket_is_reliable (NiceSocket *sock) ...@@ -288,3 +293,20 @@ socket_is_reliable (NiceSocket *sock)
return nice_socket_is_reliable (priv->base_socket); return nice_socket_is_reliable (priv->base_socket);
} }
static gboolean
socket_can_send (NiceSocket *sock, NiceAddress *addr)
{
PseudoSSLPriv *priv = sock->priv;
return nice_socket_can_send (priv->base_socket, addr);
}
static void
socket_set_writable_callback (NiceSocket *sock,
NiceSocketWritableCb callback, gpointer user_data)
{
PseudoSSLPriv *priv = sock->priv;
nice_socket_set_writable_callback (priv->base_socket, callback, user_data);
}
...@@ -249,6 +249,22 @@ nice_socket_is_reliable (NiceSocket *sock) ...@@ -249,6 +249,22 @@ nice_socket_is_reliable (NiceSocket *sock)
return sock->is_reliable (sock); return sock->is_reliable (sock);
} }
gboolean
nice_socket_can_send (NiceSocket *sock, NiceAddress *addr)
{
if (sock->can_send)
return sock->can_send (sock, addr);
return TRUE;
}
void
nice_socket_set_writable_callback (NiceSocket *sock,
NiceSocketWritableCb callback, gpointer user_data)
{
if (sock->set_writable_callback)
sock->set_writable_callback (sock, callback, user_data);
}
void void
nice_socket_free (NiceSocket *sock) nice_socket_free (NiceSocket *sock)
{ {
......
...@@ -68,6 +68,8 @@ typedef enum { ...@@ -68,6 +68,8 @@ typedef enum {
NICE_SOCKET_TYPE_TCP_SO NICE_SOCKET_TYPE_TCP_SO
} NiceSocketType; } NiceSocketType;
typedef void (*NiceSocketWritableCb) (NiceSocket *sock, gpointer user_data);
struct _NiceSocket struct _NiceSocket
{ {
NiceAddress addr; NiceAddress addr;
...@@ -83,10 +85,14 @@ struct _NiceSocket ...@@ -83,10 +85,14 @@ struct _NiceSocket
gint (*send_messages_reliable) (NiceSocket *sock, const NiceAddress *to, gint (*send_messages_reliable) (NiceSocket *sock, const NiceAddress *to,
const NiceOutputMessage *messages, guint n_messages); const NiceOutputMessage *messages, guint n_messages);
gboolean (*is_reliable) (NiceSocket *sock); gboolean (*is_reliable) (NiceSocket *sock);
gboolean (*can_send) (NiceSocket *sock, NiceAddress *addr);
void (*set_writable_callback) (NiceSocket *sock,
NiceSocketWritableCb callback, gpointer user_data);
void (*close) (NiceSocket *sock); void (*close) (NiceSocket *sock);
void *priv; void *priv;
}; };
G_GNUC_WARN_UNUSED_RESULT G_GNUC_WARN_UNUSED_RESULT
gint gint
nice_socket_recv_messages (NiceSocket *sock, nice_socket_recv_messages (NiceSocket *sock,
...@@ -111,6 +117,12 @@ nice_socket_send_reliable (NiceSocket *sock, const NiceAddress *addr, gsize len, ...@@ -111,6 +117,12 @@ nice_socket_send_reliable (NiceSocket *sock, const NiceAddress *addr, gsize len,
gboolean gboolean
nice_socket_is_reliable (NiceSocket *sock); nice_socket_is_reliable (NiceSocket *sock);
gboolean
nice_socket_can_send (NiceSocket *sock, NiceAddress *addr);
void
nice_socket_set_writable_callback (NiceSocket *sock,
NiceSocketWritableCb callback, gpointer user_data);
void void
nice_socket_free (NiceSocket *sock); nice_socket_free (NiceSocket *sock);
......
...@@ -78,6 +78,9 @@ static gint socket_send_messages (NiceSocket *sock, const NiceAddress *to, ...@@ -78,6 +78,9 @@ static gint socket_send_messages (NiceSocket *sock, const NiceAddress *to,
static gint socket_send_messages_reliable (NiceSocket *sock, static gint socket_send_messages_reliable (NiceSocket *sock,
const NiceAddress *to, const NiceOutputMessage *messages, guint n_messages); const NiceAddress *to, const NiceOutputMessage *messages, guint n_messages);
static gboolean socket_is_reliable (NiceSocket *sock); static gboolean socket_is_reliable (NiceSocket *sock);
static gboolean socket_can_send (NiceSocket *sock, NiceAddress *addr);
static void socket_set_writable_callback (NiceSocket *sock,
NiceSocketWritableCb callback, gpointer user_data);
NiceSocket * NiceSocket *
...@@ -103,6 +106,8 @@ nice_socks5_socket_new (NiceSocket *base_socket, ...@@ -103,6 +106,8 @@ nice_socks5_socket_new (NiceSocket *base_socket,
sock->send_messages_reliable = socket_send_messages_reliable; sock->send_messages_reliable = socket_send_messages_reliable;
sock->recv_messages = socket_recv_messages; sock->recv_messages = socket_recv_messages;
sock->is_reliable = socket_is_reliable; sock->is_reliable = socket_is_reliable;
sock->can_send = socket_can_send;
sock->set_writable_callback = socket_set_writable_callback;
sock->close = socket_close; sock->close = socket_close;
/* Send SOCKS5 handshake */ /* Send SOCKS5 handshake */
...@@ -459,3 +464,19 @@ socket_is_reliable (NiceSocket *sock) ...@@ -459,3 +464,19 @@ socket_is_reliable (NiceSocket *sock)
return nice_socket_is_reliable (priv->base_socket); return nice_socket_is_reliable (priv->base_socket);
} }
static gboolean
socket_can_send (NiceSocket *sock, NiceAddress *addr)
{
Socks5Priv *priv = sock->priv;
return nice_socket_can_send (priv->base_socket, addr);
}
static void
socket_set_writable_callback (NiceSocket *sock,
NiceSocketWritableCb callback, gpointer user_data)
{
Socks5Priv *priv = sock->priv;
nice_socket_set_writable_callback (priv->base_socket, callback, user_data);
}
...@@ -64,6 +64,9 @@ static gint socket_send_messages (NiceSocket *sock, const NiceAddress *to, ...@@ -64,6 +64,9 @@ static gint socket_send_messages (NiceSocket *sock, const NiceAddress *to,
static gint socket_send_messages_reliable (NiceSocket *sock, static gint socket_send_messages_reliable (NiceSocket *sock,
const NiceAddress *to, const NiceOutputMessage *messages, guint n_messages); const NiceAddress *to, const NiceOutputMessage *messages, guint n_messages);
static gboolean socket_is_reliable (NiceSocket *sock); static gboolean socket_is_reliable (NiceSocket *sock);
static gboolean socket_can_send (NiceSocket *sock, NiceAddress *addr);
static void socket_set_writable_callback (NiceSocket *sock,
NiceSocketWritableCb callback, gpointer user_data);
NiceSocket * NiceSocket *
...@@ -110,6 +113,8 @@ nice_tcp_active_socket_new (GMainContext *ctx, NiceAddress *addr) ...@@ -110,6 +113,8 @@ nice_tcp_active_socket_new (GMainContext *ctx, NiceAddress *addr)
sock->send_messages_reliable = socket_send_messages_reliable; sock->send_messages_reliable = socket_send_messages_reliable;
sock->recv_messages = socket_recv_messages; sock->recv_messages = socket_recv_messages;
sock->is_reliable = socket_is_reliable; sock->is_reliable = socket_is_reliable;
sock->can_send = socket_can_send;
sock->set_writable_callback = socket_set_writable_callback;
sock->close = socket_close; sock->close = socket_close;
return sock; return sock;
...@@ -152,6 +157,18 @@ socket_is_reliable (NiceSocket *sock) ...@@ -152,6 +157,18 @@ socket_is_reliable (NiceSocket *sock)
return TRUE; return TRUE;
} }
static gboolean
socket_can_send (NiceSocket *sock, NiceAddress *addr)
{
return FALSE;
}
static void
socket_set_writable_callback (NiceSocket *sock,
NiceSocketWritableCb callback, gpointer user_data)
{
}
NiceSocket * NiceSocket *
nice_tcp_active_socket_connect (NiceSocket *sock, NiceAddress *addr) nice_tcp_active_socket_connect (NiceSocket *sock, NiceAddress *addr)
{ {
......
...@@ -61,6 +61,8 @@ typedef struct { ...@@ -61,6 +61,8 @@ typedef struct {
GSource *io_source; GSource *io_source;
gboolean error; gboolean error;
gboolean reliable; gboolean reliable;
NiceSocketWritableCb writable_cb;
gpointer writable_data;
} TcpPriv; } TcpPriv;
#define MAX_QUEUE_LENGTH 20 #define MAX_QUEUE_LENGTH 20
...@@ -73,6 +75,9 @@ static gint socket_send_messages (NiceSocket *sock, const NiceAddress *to, ...@@ -73,6 +75,9 @@ static gint socket_send_messages (NiceSocket *sock, const NiceAddress *to,
static gint socket_send_messages_reliable (NiceSocket *sock, static gint socket_send_messages_reliable (NiceSocket *sock,
const NiceAddress *to, const NiceOutputMessage *messages, guint n_messages); const NiceAddress *to, const NiceOutputMessage *messages, guint n_messages);
static gboolean socket_is_reliable (NiceSocket *sock); static gboolean socket_is_reliable (NiceSocket *sock);
static gboolean socket_can_send (NiceSocket *sock, NiceAddress *addr);
static void socket_set_writable_callback (NiceSocket *sock,
NiceSocketWritableCb callback, gpointer user_data);
static gboolean socket_send_more (GSocket *gsocket, GIOCondition condition, static gboolean socket_send_more (GSocket *gsocket, GIOCondition condition,
gpointer data); gpointer data);
...@@ -95,6 +100,8 @@ nice_tcp_bsd_socket_new_from_gsock (GMainContext *ctx, GSocket *gsock, ...@@ -95,6 +100,8 @@ nice_tcp_bsd_socket_new_from_gsock (GMainContext *ctx, GSocket *gsock,
priv->remote_addr = *remote_addr; priv->remote_addr = *remote_addr;
priv->error = FALSE; priv->error = FALSE;
priv->reliable = reliable; priv->reliable = reliable;
priv->writable_cb = NULL;
priv->writable_data = NULL;
sock->type = NICE_SOCKET_TYPE_TCP_BSD; sock->type = NICE_SOCKET_TYPE_TCP_BSD;
sock->fileno = g_object_ref (gsock); sock->fileno = g_object_ref (gsock);
...@@ -103,6 +110,8 @@ nice_tcp_bsd_socket_new_from_gsock (GMainContext *ctx, GSocket *gsock, ...@@ -103,6 +110,8 @@ nice_tcp_bsd_socket_new_from_gsock (GMainContext *ctx, GSocket *gsock,
sock->send_messages_reliable = socket_send_messages_reliable; sock->send_messages_reliable = socket_send_messages_reliable;
sock->recv_messages = socket_recv_messages; sock->recv_messages = socket_recv_messages;
sock->is_reliable = socket_is_reliable; sock->is_reliable = socket_is_reliable;
sock->can_send = socket_can_send;
sock->set_writable_callback = socket_set_writable_callback;
sock->close = socket_close; sock->close = socket_close;
return sock; return sock;
...@@ -374,13 +383,23 @@ socket_is_reliable (NiceSocket *sock) ...@@ -374,13 +383,23 @@ socket_is_reliable (NiceSocket *sock)
return priv->reliable; return priv->reliable;
} }
static gboolean
socket_can_send (NiceSocket *sock, NiceAddress *addr)
{
TcpPriv *priv = sock->priv;
/* return g_queue_is_empty (&priv->send_queue);
* Returns: }
* -1 = error
* 0 = have more to send static void
* 1 = sent everything socket_set_writable_callback (NiceSocket *sock,
*/ NiceSocketWritableCb callback, gpointer user_data)
{
TcpPriv *priv = sock->priv;
priv->writable_cb = callback;
priv->writable_data = user_data;
}
static gboolean static gboolean
socket_send_more ( socket_send_more (
...@@ -409,6 +428,10 @@ socket_send_more ( ...@@ -409,6 +428,10 @@ socket_send_more (
priv->io_source = NULL; priv->io_source = NULL;
agent_unlock (); agent_unlock ();
if (priv->writable_cb)
priv->writable_cb (sock, priv->writable_data);
return FALSE; return FALSE;
} }
......
...@@ -41,7 +41,6 @@ ...@@ -41,7 +41,6 @@
G_BEGIN_DECLS G_BEGIN_DECLS
NiceSocket * NiceSocket *
nice_tcp_bsd_socket_new (GMainContext *ctx, NiceAddress *remote_addr, nice_tcp_bsd_socket_new (GMainContext *ctx, NiceAddress *remote_addr,
NiceAddress *local_addr, gboolean reliable); NiceAddress *local_addr, gboolean reliable);
......
...@@ -53,6 +53,8 @@ ...@@ -53,6 +53,8 @@
typedef struct { typedef struct {
GMainContext *context; GMainContext *context;
GHashTable *connections; GHashTable *connections;
NiceSocketWritableCb writable_cb;
gpointer writable_data;
} TcpPassivePriv; } TcpPassivePriv;
...@@ -64,7 +66,13 @@ static gint socket_send_messages (NiceSocket *sock, const NiceAddress *to, ...@@ -64,7 +66,13 @@ static gint socket_send_messages (NiceSocket *sock, const NiceAddress *to,
static gint socket_send_messages_reliable (NiceSocket *sock, static gint socket_send_messages_reliable (NiceSocket *sock,
const NiceAddress *to, const NiceOutputMessage *messages, guint n_messages); const NiceAddress *to, const NiceOutputMessage *messages, guint n_messages);
static gboolean socket_is_reliable (NiceSocket *sock); static gboolean socket_is_reliable (NiceSocket *sock);
static gboolean socket_can_send (NiceSocket *sock, NiceAddress *addr);
static void socket_set_writable_callback (NiceSocket *sock,
NiceSocketWritableCb callback, gpointer user_data);
static guint nice_address_hash (const NiceAddress * key); static guint nice_address_hash (const NiceAddress * key);
static void _set_child_callbacks (NiceAddress *addr, NiceSocket *child,
NiceSocket *sock);
NiceSocket * NiceSocket *
nice_tcp_passive_socket_new (GMainContext *ctx, NiceAddress *addr) nice_tcp_passive_socket_new (GMainContext *ctx, NiceAddress *addr)
...@@ -145,6 +153,8 @@ nice_tcp_passive_socket_new (GMainContext *ctx, NiceAddress *addr) ...@@ -145,6 +153,8 @@ nice_tcp_passive_socket_new (GMainContext *ctx, NiceAddress *addr)
priv->connections = g_hash_table_new_full ((GHashFunc) nice_address_hash, priv->connections = g_hash_table_new_full ((GHashFunc) nice_address_hash,
(GEqualFunc) nice_address_equal, ( (GEqualFunc) nice_address_equal, (
GDestroyNotify) nice_address_free, NULL); GDestroyNotify) nice_address_free, NULL);
priv->writable_cb = NULL;
priv->writable_data = NULL;
sock->type = NICE_SOCKET_TYPE_TCP_PASSIVE; sock->type = NICE_SOCKET_TYPE_TCP_PASSIVE;
sock->fileno = gsock; sock->fileno = gsock;
...@@ -152,6 +162,8 @@ nice_tcp_passive_socket_new (GMainContext *ctx, NiceAddress *addr) ...@@ -152,6 +162,8 @@ nice_tcp_passive_socket_new (GMainContext *ctx, NiceAddress *addr)
sock->send_messages_reliable = socket_send_messages_reliable; sock->send_messages_reliable = socket_send_messages_reliable;
sock->recv_messages = socket_recv_messages; sock->recv_messages = socket_recv_messages;
sock->is_reliable = socket_is_reliable; sock->is_reliable = socket_is_reliable;
sock->can_send = socket_can_send;
sock->set_writable_callback = socket_set_writable_callback;
sock->close = socket_close; sock->close = socket_close;
return sock; return sock;
...@@ -208,6 +220,42 @@ socket_is_reliable (NiceSocket *sock) ...@@ -208,6 +220,42 @@ socket_is_reliable (NiceSocket *sock)
return TRUE; return TRUE;
} }
static gboolean
socket_can_send (NiceSocket *sock, NiceAddress *addr)
{
TcpPassivePriv *priv = sock->priv;
NiceSocket *peer_socket = NULL;
/* FIXME: Danger if child socket was closed */
if (addr)
peer_socket = g_hash_table_lookup (priv->connections, addr);
if (peer_socket)
return nice_socket_can_send (peer_socket, addr);
return FALSE;
}
static void
_set_child_callbacks (NiceAddress *addr, NiceSocket *child, NiceSocket *sock)
{
TcpPassivePriv *priv = sock->priv;
/* FIXME: Danger if child socket was closed */
nice_socket_set_writable_callback (child, priv->writable_cb,
priv->writable_data);
}
static void
socket_set_writable_callback (NiceSocket *sock,
NiceSocketWritableCb callback, gpointer user_data)
{
TcpPassivePriv *priv = sock->priv;
priv->writable_cb = callback;
priv->writable_data = user_data;
g_hash_table_foreach (priv->connections, (GHFunc) _set_child_callbacks, sock);
}
NiceSocket * NiceSocket *
nice_tcp_passive_socket_accept (NiceSocket *sock) nice_tcp_passive_socket_accept (NiceSocket *sock)
{ {
...@@ -248,6 +296,7 @@ nice_tcp_passive_socket_accept (NiceSocket *sock) ...@@ -248,6 +296,7 @@ nice_tcp_passive_socket_accept (NiceSocket *sock)
if (new_socket) { if (new_socket) {
NiceAddress *key = nice_address_dup (&remote_addr); NiceAddress *key = nice_address_dup (&remote_addr);
_set_child_callbacks (key, new_socket, sock);
g_hash_table_insert (priv->connections, key, new_socket); g_hash_table_insert (priv->connections, key, new_socket);
} }
return new_socket; return new_socket;
......
...@@ -64,6 +64,9 @@ static gint socket_send_messages (NiceSocket *sock, const NiceAddress *to, ...@@ -64,6 +64,9 @@ static gint socket_send_messages (NiceSocket *sock, const NiceAddress *to,
static gint socket_send_messages_reliable (NiceSocket *sock, static gint socket_send_messages_reliable (NiceSocket *sock,
const NiceAddress *to, const NiceOutputMessage *messages, guint n_messages); const NiceAddress *to, const NiceOutputMessage *messages, guint n_messages);
static gboolean socket_is_reliable (NiceSocket *sock); static gboolean socket_is_reliable (NiceSocket *sock);
static gboolean socket_can_send (NiceSocket *sock, NiceAddress *addr);
static void socket_set_writable_callback (NiceSocket *sock,
NiceSocketWritableCb callback, gpointer user_data);
struct UdpBsdSocketPrivate struct UdpBsdSocketPrivate
{ {
...@@ -149,6 +152,8 @@ nice_udp_bsd_socket_new (NiceAddress *addr) ...@@ -149,6 +152,8 @@ nice_udp_bsd_socket_new (NiceAddress *addr)
sock->send_messages_reliable = socket_send_messages_reliable; sock->send_messages_reliable = socket_send_messages_reliable;
sock->recv_messages = socket_recv_messages; sock->recv_messages = socket_recv_messages;
sock->is_reliable = socket_is_reliable; sock->is_reliable = socket_is_reliable;
sock->can_send = socket_can_send;
sock->set_writable_callback = socket_set_writable_callback;
sock->close = socket_close; sock->close = socket_close;
return sock; return sock;
...@@ -309,3 +314,15 @@ socket_is_reliable (NiceSocket *sock) ...@@ -309,3 +314,15 @@ socket_is_reliable (NiceSocket *sock)
return FALSE; return FALSE;
} }
static gboolean
socket_can_send (NiceSocket *sock, NiceAddress *addr)
{
return TRUE;
}
static void
socket_set_writable_callback (NiceSocket *sock,
NiceSocketWritableCb callback, gpointer user_data)
{
}
...@@ -83,6 +83,9 @@ static gint socket_send_messages (NiceSocket *sock, const NiceAddress *to, ...@@ -83,6 +83,9 @@ static gint socket_send_messages (NiceSocket *sock, const NiceAddress *to,
static gint socket_send_messages_reliable (NiceSocket *sock, static gint socket_send_messages_reliable (NiceSocket *sock,
const NiceAddress *to, const NiceOutputMessage *messages, guint n_messages); const NiceAddress *to, const NiceOutputMessage *messages, guint n_messages);
static gboolean socket_is_reliable (NiceSocket *sock); static gboolean socket_is_reliable (NiceSocket *sock);
static gboolean socket_can_send (NiceSocket *sock, NiceAddress *addr);
static void socket_set_writable_callback (NiceSocket *sock,
NiceSocketWritableCb callback, gpointer user_data);
NiceSocket * NiceSocket *
nice_udp_turn_over_tcp_socket_new (NiceSocket *base_socket, nice_udp_turn_over_tcp_socket_new (NiceSocket *base_socket,
...@@ -102,6 +105,8 @@ nice_udp_turn_over_tcp_socket_new (NiceSocket *base_socket, ...@@ -102,6 +105,8 @@ nice_udp_turn_over_tcp_socket_new (NiceSocket *base_socket,
sock->send_messages_reliable = socket_send_messages_reliable; sock->send_messages_reliable = socket_send_messages_reliable;
sock->recv_messages = socket_recv_messages; sock->recv_messages = socket_recv_messages;
sock->is_reliable = socket_is_reliable; sock->is_reliable = socket_is_reliable;
sock->can_send = socket_can_send;
sock->set_writable_callback = socket_set_writable_callback;
sock->close = socket_close; sock->close = socket_close;
return sock; return sock;
...@@ -420,3 +425,19 @@ socket_is_reliable (NiceSocket *sock) ...@@ -420,3 +425,19 @@ socket_is_reliable (NiceSocket *sock)
return nice_socket_is_reliable (priv->base_socket); return nice_socket_is_reliable (priv->base_socket);
} }
static gboolean
socket_can_send (NiceSocket *sock, NiceAddress *addr)
{
TurnTcpPriv *priv = sock->priv;
return nice_socket_can_send (priv->base_socket, addr);
}
static void
socket_set_writable_callback (NiceSocket *sock,
NiceSocketWritableCb callback, gpointer user_data)
{
TurnTcpPriv *priv = sock->priv;
nice_socket_set_writable_callback (priv->base_socket, callback, user_data);
}
...@@ -122,6 +122,9 @@ static gint socket_send_messages (NiceSocket *sock, const NiceAddress *to, ...@@ -122,6 +122,9 @@ static gint socket_send_messages (NiceSocket *sock, const NiceAddress *to,
static gint socket_send_messages_reliable (NiceSocket *sock, static gint socket_send_messages_reliable (NiceSocket *sock,
const NiceAddress *to, const NiceOutputMessage *messages, guint n_messages); const NiceAddress *to, const NiceOutputMessage *messages, guint n_messages);
static gboolean socket_is_reliable (NiceSocket *sock); static gboolean socket_is_reliable (NiceSocket *sock);
static gboolean socket_can_send (NiceSocket *sock, NiceAddress *addr);
static void socket_set_writable_callback (NiceSocket *sock,
NiceSocketWritableCb callback, gpointer user_data);
static void priv_process_pending_bindings (UdpTurnPriv *priv); static void priv_process_pending_bindings (UdpTurnPriv *priv);
static gboolean priv_retransmissions_tick_unlocked (UdpTurnPriv *priv); static gboolean priv_retransmissions_tick_unlocked (UdpTurnPriv *priv);
...@@ -238,6 +241,8 @@ nice_udp_turn_socket_new (GMainContext *ctx, NiceAddress *addr, ...@@ -238,6 +241,8 @@ nice_udp_turn_socket_new (GMainContext *ctx, NiceAddress *addr,
sock->send_messages_reliable = socket_send_messages_reliable; sock->send_messages_reliable = socket_send_messages_reliable;
sock->recv_messages = socket_recv_messages; sock->recv_messages = socket_recv_messages;
sock->is_reliable = socket_is_reliable; sock->is_reliable = socket_is_reliable;
sock->can_send = socket_can_send;
sock->set_writable_callback = socket_set_writable_callback;
sock->close = socket_close; sock->close = socket_close;
sock->priv = (void *) priv; sock->priv = (void *) priv;
...@@ -914,6 +919,23 @@ socket_is_reliable (NiceSocket *sock) ...@@ -914,6 +919,23 @@ socket_is_reliable (NiceSocket *sock)
return nice_socket_is_reliable (priv->base_socket); return nice_socket_is_reliable (priv->base_socket);
} }
static gboolean
socket_can_send (NiceSocket *sock, NiceAddress *addr)
{
UdpTurnPriv *priv = sock->priv;
return nice_socket_can_send (priv->base_socket, addr);
}
static void
socket_set_writable_callback (NiceSocket *sock,
NiceSocketWritableCb callback, gpointer user_data)
{
UdpTurnPriv *priv = sock->priv;
nice_socket_set_writable_callback (priv->base_socket, callback, user_data);
}
static gboolean static gboolean
priv_forget_send_request (gpointer pointer) priv_forget_send_request (gpointer pointer)
{ {
......
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