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

Allow tcp-bsd to act as reliable or non reliable transport and fix is_reliable on other sockets

parent 48428cda
...@@ -1788,7 +1788,8 @@ priv_add_new_candidate_discovery_turn (NiceAgent *agent, ...@@ -1788,7 +1788,8 @@ priv_add_new_candidate_discovery_turn (NiceAgent *agent,
agent->proxy_ip != NULL && agent->proxy_ip != NULL &&
nice_address_set_from_string (&proxy_server, agent->proxy_ip)) { nice_address_set_from_string (&proxy_server, agent->proxy_ip)) {
nice_address_set_port (&proxy_server, agent->proxy_port); nice_address_set_port (&proxy_server, agent->proxy_port);
nicesock = nice_tcp_bsd_socket_new (agent->main_context, &proxy_server); nicesock = nice_tcp_bsd_socket_new (agent->main_context, &proxy_server,
FALSE);
if (nicesock) { if (nicesock) {
_priv_set_socket_tos (agent, nicesock, stream->tos); _priv_set_socket_tos (agent, nicesock, stream->tos);
...@@ -1806,7 +1807,8 @@ priv_add_new_candidate_discovery_turn (NiceAgent *agent, ...@@ -1806,7 +1807,8 @@ priv_add_new_candidate_discovery_turn (NiceAgent *agent,
} }
if (nicesock == NULL) { if (nicesock == NULL) {
nicesock = nice_tcp_bsd_socket_new (agent->main_context, &turn->server); nicesock = nice_tcp_bsd_socket_new (agent->main_context, &turn->server,
FALSE);
if (nicesock) if (nicesock)
_priv_set_socket_tos (agent, nicesock, stream->tos); _priv_set_socket_tos (agent, nicesock, stream->tos);
......
...@@ -598,7 +598,9 @@ socket_send_messages (NiceSocket *sock, const NiceAddress *to, ...@@ -598,7 +598,9 @@ socket_send_messages (NiceSocket *sock, const NiceAddress *to,
static gboolean static gboolean
socket_is_reliable (NiceSocket *sock) socket_is_reliable (NiceSocket *sock)
{ {
return TRUE; HttpPriv *priv = sock->priv;
return nice_socket_is_reliable (priv->base_socket);
} }
......
...@@ -201,21 +201,23 @@ socket_send_messages (NiceSocket *sock, const NiceAddress *to, ...@@ -201,21 +201,23 @@ socket_send_messages (NiceSocket *sock, const NiceAddress *to,
/* Fast path: pass directly through to the base socket once the handshake is /* Fast path: pass directly through to the base socket once the handshake is
* complete. */ * complete. */
if (priv->base_socket == NULL) if (priv->base_socket == NULL)
return FALSE; return -1;
return nice_socket_send_messages (priv->base_socket, to, messages, return nice_socket_send_messages (priv->base_socket, to, messages,
n_messages); n_messages);
} else { } else {
add_to_be_sent (sock, to, messages, n_messages); add_to_be_sent (sock, to, messages, n_messages);
} }
return TRUE; return n_messages;
} }
static gboolean static gboolean
socket_is_reliable (NiceSocket *sock) socket_is_reliable (NiceSocket *sock)
{ {
return TRUE; PseudoSSLPriv *priv = sock->priv;
return nice_socket_is_reliable (priv->base_socket);
} }
......
...@@ -445,7 +445,9 @@ socket_send_messages (NiceSocket *sock, const NiceAddress *to, ...@@ -445,7 +445,9 @@ socket_send_messages (NiceSocket *sock, const NiceAddress *to,
static gboolean static gboolean
socket_is_reliable (NiceSocket *sock) socket_is_reliable (NiceSocket *sock)
{ {
return TRUE; Socks5Priv *priv = sock->priv;
return nice_socket_is_reliable (priv->base_socket);
} }
......
...@@ -59,6 +59,7 @@ typedef struct { ...@@ -59,6 +59,7 @@ typedef struct {
GMainContext *context; GMainContext *context;
GSource *io_source; GSource *io_source;
gboolean error; gboolean error;
gboolean reliable;
} TcpPriv; } TcpPriv;
struct to_be_sent { struct to_be_sent {
...@@ -84,7 +85,7 @@ static gboolean socket_send_more (GSocket *gsocket, GIOCondition condition, ...@@ -84,7 +85,7 @@ static gboolean socket_send_more (GSocket *gsocket, GIOCondition condition,
gpointer data); gpointer data);
NiceSocket * NiceSocket *
nice_tcp_bsd_socket_new (GMainContext *ctx, NiceAddress *addr) nice_tcp_bsd_socket_new (GMainContext *ctx, NiceAddress *addr, gboolean reliable)
{ {
union { union {
struct sockaddr_storage storage; struct sockaddr_storage storage;
...@@ -171,6 +172,7 @@ nice_tcp_bsd_socket_new (GMainContext *ctx, NiceAddress *addr) ...@@ -171,6 +172,7 @@ nice_tcp_bsd_socket_new (GMainContext *ctx, NiceAddress *addr)
priv->context = g_main_context_ref (ctx); priv->context = g_main_context_ref (ctx);
priv->server_addr = *addr; priv->server_addr = *addr;
priv->error = FALSE; priv->error = FALSE;
priv->reliable = reliable;
sock->type = NICE_SOCKET_TYPE_TCP_BSD; sock->type = NICE_SOCKET_TYPE_TCP_BSD;
sock->fileno = gsock; sock->fileno = gsock;
...@@ -292,6 +294,9 @@ socket_send_message (NiceSocket *sock, const NiceOutputMessage *message) ...@@ -292,6 +294,9 @@ socket_send_message (NiceSocket *sock, const NiceOutputMessage *message)
add_to_be_sent (sock, message, ret, message_len, TRUE); add_to_be_sent (sock, message, ret, message_len, TRUE);
ret = message_len; ret = message_len;
} }
} else if (priv->reliable) {
/* Reliable TCP, so we shouldn't drop any messages or queue them */
ret = 0;
} else { } else {
/* FIXME: This dropping will break http/socks5/etc /* FIXME: This dropping will break http/socks5/etc
* We probably need a way to the upper layer to control reliability * We probably need a way to the upper layer to control reliability
...@@ -350,7 +355,9 @@ socket_send_messages (NiceSocket *sock, const NiceAddress *to, ...@@ -350,7 +355,9 @@ socket_send_messages (NiceSocket *sock, const NiceAddress *to,
static gboolean static gboolean
socket_is_reliable (NiceSocket *sock) socket_is_reliable (NiceSocket *sock)
{ {
return TRUE; TcpPriv *priv = sock->priv;
return priv->reliable;
} }
......
...@@ -43,8 +43,7 @@ G_BEGIN_DECLS ...@@ -43,8 +43,7 @@ G_BEGIN_DECLS
NiceSocket * NiceSocket *
nice_tcp_bsd_socket_new (GMainContext *ctx, NiceAddress *addr); nice_tcp_bsd_socket_new (GMainContext *ctx, NiceAddress *addr, gboolean reliable);
G_END_DECLS G_END_DECLS
......
...@@ -314,6 +314,8 @@ socket_send_messages (NiceSocket *sock, const NiceAddress *to, ...@@ -314,6 +314,8 @@ socket_send_messages (NiceSocket *sock, const NiceAddress *to,
static gboolean static gboolean
socket_is_reliable (NiceSocket *sock) socket_is_reliable (NiceSocket *sock)
{ {
return TRUE; TurnTcpPriv *priv = sock->priv;
return nice_socket_is_reliable (priv->base_socket);
} }
...@@ -773,6 +773,7 @@ static gboolean ...@@ -773,6 +773,7 @@ static gboolean
socket_is_reliable (NiceSocket *sock) socket_is_reliable (NiceSocket *sock)
{ {
TurnPriv *priv = (TurnPriv *) sock->priv; TurnPriv *priv = (TurnPriv *) sock->priv;
return nice_socket_is_reliable (priv->base_socket); return nice_socket_is_reliable (priv->base_socket);
} }
......
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