Commit bf30b2e9 authored by Youness Alaoui's avatar Youness Alaoui

Fix coding style

parent 041ae5b3
...@@ -2292,7 +2292,7 @@ _nice_agent_recv ( ...@@ -2292,7 +2292,7 @@ _nice_agent_recv (
gchar tmpbuf[INET6_ADDRSTRLEN]; gchar tmpbuf[INET6_ADDRSTRLEN];
nice_address_to_string (&from, tmpbuf); nice_address_to_string (&from, tmpbuf);
nice_debug ("Agent %p : Packet received on local socket %u from [%s]:%u (%u octets).", agent, nice_debug ("Agent %p : Packet received on local socket %u from [%s]:%u (%u octets).", agent,
g_socket_get_fd(socket->fileno), tmpbuf, nice_address_get_port (&from), len); g_socket_get_fd (socket->fileno), tmpbuf, nice_address_get_port (&from), len);
} }
#endif #endif
...@@ -2900,13 +2900,13 @@ nice_agent_set_selected_remote_candidate ( ...@@ -2900,13 +2900,13 @@ nice_agent_set_selected_remote_candidate (
void void
_priv_set_socket_tos (NiceAgent *agent, NiceSocket *sock, gint tos) _priv_set_socket_tos (NiceAgent *agent, NiceSocket *sock, gint tos)
{ {
if (setsockopt (g_socket_get_fd(sock->fileno), IPPROTO_IP, if (setsockopt (g_socket_get_fd (sock->fileno), IPPROTO_IP,
IP_TOS, (const char *) &tos, sizeof (tos)) < 0) { IP_TOS, (const char *) &tos, sizeof (tos)) < 0) {
nice_debug ("Agent %p: Could not set socket ToS", agent, nice_debug ("Agent %p: Could not set socket ToS", agent,
g_strerror (errno)); g_strerror (errno));
} }
#ifdef IPV6_TCLASS #ifdef IPV6_TCLASS
if (setsockopt (g_socket_get_fd(sock->fileno), IPPROTO_IPV6, if (setsockopt (g_socket_get_fd (sock->fileno), IPPROTO_IPV6,
IPV6_TCLASS, (const char *) &tos, sizeof (tos)) < 0) { IPV6_TCLASS, (const char *) &tos, sizeof (tos)) < 0) {
nice_debug ("Agent %p: Could not set IPV6 socket ToS", agent, nice_debug ("Agent %p: Could not set IPV6 socket ToS", agent,
g_strerror (errno)); g_strerror (errno));
......
...@@ -102,18 +102,20 @@ nice_tcp_bsd_socket_new (GMainContext *ctx, NiceAddress *addr) ...@@ -102,18 +102,20 @@ nice_tcp_bsd_socket_new (GMainContext *ctx, NiceAddress *addr)
sock = g_slice_new0 (NiceSocket); sock = g_slice_new0 (NiceSocket);
nice_address_copy_to_sockaddr(addr, (struct sockaddr *)&name); nice_address_copy_to_sockaddr (addr, (struct sockaddr *)&name);
if (gsock == NULL) { if (gsock == NULL) {
if (name.ss_family == AF_UNSPEC || name.ss_family == AF_INET) { if (name.ss_family == AF_UNSPEC || name.ss_family == AF_INET) {
gsock = g_socket_new(G_SOCKET_FAMILY_IPV4, G_SOCKET_TYPE_STREAM, G_SOCKET_PROTOCOL_TCP, NULL); gsock = g_socket_new (G_SOCKET_FAMILY_IPV4, G_SOCKET_TYPE_STREAM,
G_SOCKET_PROTOCOL_TCP, NULL);
name.ss_family = AF_INET; name.ss_family = AF_INET;
#ifdef HAVE_SA_LEN #ifdef HAVE_SA_LEN
name.ss_len = sizeof (struct sockaddr_in); name.ss_len = sizeof (struct sockaddr_in);
#endif #endif
} else if (name.ss_family == AF_INET6) { } else if (name.ss_family == AF_INET6) {
gsock = g_socket_new(G_SOCKET_FAMILY_IPV6, G_SOCKET_TYPE_STREAM, G_SOCKET_PROTOCOL_TCP, NULL); gsock = g_socket_new (G_SOCKET_FAMILY_IPV6, G_SOCKET_TYPE_STREAM,
G_SOCKET_PROTOCOL_TCP, NULL);
name.ss_family = AF_INET6; name.ss_family = AF_INET6;
#ifdef HAVE_SA_LEN #ifdef HAVE_SA_LEN
name.ss_len = sizeof (struct sockaddr_in6); name.ss_len = sizeof (struct sockaddr_in6);
...@@ -121,10 +123,10 @@ nice_tcp_bsd_socket_new (GMainContext *ctx, NiceAddress *addr) ...@@ -121,10 +123,10 @@ nice_tcp_bsd_socket_new (GMainContext *ctx, NiceAddress *addr)
} }
} }
if(gsock == NULL) { if (gsock == NULL) {
g_slice_free (NiceSocket, sock); g_slice_free (NiceSocket, sock);
return NULL; return NULL;
} }
/* GSocket: All socket file descriptors are set to be close-on-exec. */ /* GSocket: All socket file descriptors are set to be close-on-exec. */
g_socket_set_blocking(gsock, false); g_socket_set_blocking(gsock, false);
...@@ -155,8 +157,8 @@ nice_tcp_bsd_socket_new (GMainContext *ctx, NiceAddress *addr) ...@@ -155,8 +157,8 @@ nice_tcp_bsd_socket_new (GMainContext *ctx, NiceAddress *addr)
if(gaddr == NULL) if(gaddr == NULL)
{ {
g_slice_free (NiceSocket, sock); g_slice_free (NiceSocket, sock);
g_socket_close(gsock, NULL); g_socket_close (gsock, NULL);
g_object_unref(gsock); g_object_unref (gsock);
return NULL; return NULL;
} }
...@@ -167,7 +169,7 @@ nice_tcp_bsd_socket_new (GMainContext *ctx, NiceAddress *addr) ...@@ -167,7 +169,7 @@ nice_tcp_bsd_socket_new (GMainContext *ctx, NiceAddress *addr)
g_object_unref(gaddr); g_object_unref(gaddr);
nice_address_set_from_sockaddr (&sock->addr, (struct sockaddr *)&name); nice_address_set_from_sockaddr (&sock->addr, (struct sockaddr *)&name);
sock->priv = priv = g_slice_new0 (TcpPriv); sock->priv = priv = g_slice_new0 (TcpPriv);
priv->context = g_main_context_ref (ctx); priv->context = g_main_context_ref (ctx);
...@@ -189,9 +191,9 @@ socket_close (NiceSocket *sock) ...@@ -189,9 +191,9 @@ socket_close (NiceSocket *sock)
{ {
TcpPriv *priv = sock->priv; TcpPriv *priv = sock->priv;
if(sock->fileno) { if (sock->fileno) {
g_socket_close(sock->fileno, NULL); g_socket_close (sock->fileno, NULL);
g_object_unref(sock->fileno); g_object_unref (sock->fileno);
sock->fileno = NULL; sock->fileno = NULL;
} }
if (priv->io_source) { if (priv->io_source) {
...@@ -218,7 +220,7 @@ socket_recv (NiceSocket *sock, NiceAddress *from, guint len, gchar *buf) ...@@ -218,7 +220,7 @@ socket_recv (NiceSocket *sock, NiceAddress *from, guint len, gchar *buf)
if (priv->error) if (priv->error)
return -1; return -1;
ret = g_socket_receive(sock->fileno, buf, len, NULL, &gerr); ret = g_socket_receive (sock->fileno, buf, len, NULL, &gerr);
/* recv returns 0 when the peer performed a shutdown.. we must return -1 here /* recv returns 0 when the peer performed a shutdown.. we must return -1 here
* so that the agent destroys the g_source */ * so that the agent destroys the g_source */
...@@ -228,10 +230,10 @@ socket_recv (NiceSocket *sock, NiceAddress *from, guint len, gchar *buf) ...@@ -228,10 +230,10 @@ socket_recv (NiceSocket *sock, NiceAddress *from, guint len, gchar *buf)
} }
if (ret < 0) { if (ret < 0) {
if(g_error_matches(gerr, G_IO_ERROR, G_IO_ERROR_WOULD_BLOCK)) if(g_error_matches (gerr, G_IO_ERROR, G_IO_ERROR_WOULD_BLOCK))
ret = 0; ret = 0;
g_error_free(gerr); g_error_free (gerr);
return ret; return ret;
} }
...@@ -259,15 +261,15 @@ socket_send (NiceSocket *sock, const NiceAddress *to, ...@@ -259,15 +261,15 @@ socket_send (NiceSocket *sock, const NiceAddress *to,
/* First try to send the data, don't send it later if it can be sent now /* First try to send the data, don't send it later if it can be sent now
this way we avoid allocating memory on every send */ this way we avoid allocating memory on every send */
if (g_queue_is_empty (&priv->send_queue)) { if (g_queue_is_empty (&priv->send_queue)) {
ret = g_socket_send (sock->fileno, buf, len, NULL, &gerr); ret = g_socket_send (sock->fileno, buf, len, NULL, &gerr);
if (ret < 0) { if (ret < 0) {
if(g_error_matches(gerr, G_IO_ERROR, G_IO_ERROR_WOULD_BLOCK) if(g_error_matches (gerr, G_IO_ERROR, G_IO_ERROR_WOULD_BLOCK)
|| g_error_matches(gerr, G_IO_ERROR, G_IO_ERROR_FAILED)) { || g_error_matches (gerr, G_IO_ERROR, G_IO_ERROR_FAILED)) {
add_to_be_sent (sock, buf, len, FALSE); add_to_be_sent (sock, buf, len, FALSE);
g_error_free(gerr); g_error_free (gerr);
return TRUE; return TRUE;
} else { } else {
g_error_free(gerr); g_error_free (gerr);
return FALSE; return FALSE;
} }
} else if ((guint)ret < len) { } else if ((guint)ret < len) {
...@@ -335,19 +337,20 @@ socket_send_more ( ...@@ -335,19 +337,20 @@ socket_send_more (
if(condition & G_IO_HUP) { if(condition & G_IO_HUP) {
/* connection hangs up */ /* connection hangs up */
ret = -1; ret = -1;
} } else {
else
ret = g_socket_send (sock->fileno, tbs->buf, tbs->length, NULL, &gerr); ret = g_socket_send (sock->fileno, tbs->buf, tbs->length, NULL, &gerr);
}
if (ret < 0) { if (ret < 0) {
if(gerr!=NULL && g_error_matches(gerr, G_IO_ERROR, G_IO_ERROR_WOULD_BLOCK)) { if(gerr != NULL &&
g_error_matches (gerr, G_IO_ERROR, G_IO_ERROR_WOULD_BLOCK)) {
add_to_be_sent (sock, tbs->buf, tbs->length, TRUE); add_to_be_sent (sock, tbs->buf, tbs->length, TRUE);
g_free (tbs->buf); g_free (tbs->buf);
g_slice_free (struct to_be_sent, tbs); g_slice_free (struct to_be_sent, tbs);
g_error_free(gerr); g_error_free (gerr);
break; break;
} }
g_error_free(gerr); g_error_free (gerr);
} else if (ret < (int) tbs->length) { } else if (ret < (int) tbs->length) {
add_to_be_sent (sock, tbs->buf + ret, tbs->length - ret, TRUE); add_to_be_sent (sock, tbs->buf + ret, tbs->length - ret, TRUE);
g_free (tbs->buf); g_free (tbs->buf);
......
...@@ -81,24 +81,25 @@ nice_udp_bsd_socket_new (NiceAddress *addr) ...@@ -81,24 +81,25 @@ nice_udp_bsd_socket_new (NiceAddress *addr)
} }
if (name.ss_family == AF_UNSPEC || name.ss_family == AF_INET) { if (name.ss_family == AF_UNSPEC || name.ss_family == AF_INET) {
gsock = g_socket_new(G_SOCKET_FAMILY_IPV4, G_SOCKET_TYPE_DATAGRAM, G_SOCKET_PROTOCOL_UDP, NULL); gsock = g_socket_new (G_SOCKET_FAMILY_IPV4, G_SOCKET_TYPE_DATAGRAM,
G_SOCKET_PROTOCOL_UDP, NULL);
name.ss_family = AF_INET; name.ss_family = AF_INET;
#ifdef HAVE_SA_LEN #ifdef HAVE_SA_LEN
name.ss_len = sizeof (struct sockaddr_in); name.ss_len = sizeof (struct sockaddr_in);
#endif #endif
} else if (name.ss_family == AF_INET6) { } else if (name.ss_family == AF_INET6) {
gsock = g_socket_new(G_SOCKET_FAMILY_IPV6, G_SOCKET_TYPE_DATAGRAM, G_SOCKET_PROTOCOL_UDP, NULL); gsock = g_socket_new (G_SOCKET_FAMILY_IPV6, G_SOCKET_TYPE_DATAGRAM,
G_SOCKET_PROTOCOL_UDP, NULL);
name.ss_family = AF_INET6; name.ss_family = AF_INET6;
#ifdef HAVE_SA_LEN #ifdef HAVE_SA_LEN
name.ss_len = sizeof (struct sockaddr_in6); name.ss_len = sizeof (struct sockaddr_in6);
#endif #endif
} }
if(gsock == NULL) { if (gsock == NULL) {
g_slice_free (NiceSocket, sock); g_slice_free (NiceSocket, sock);
return NULL; return NULL;
} }
/* GSocket: All socket file descriptors are set to be close-on-exec. */ /* GSocket: All socket file descriptors are set to be close-on-exec. */
g_socket_set_blocking(gsock, false); g_socket_set_blocking(gsock, false);
...@@ -106,18 +107,18 @@ nice_udp_bsd_socket_new (NiceAddress *addr) ...@@ -106,18 +107,18 @@ nice_udp_bsd_socket_new (NiceAddress *addr)
sizeof(struct sockaddr_in6); sizeof(struct sockaddr_in6);
gret = g_socket_bind(gsock, g_socket_address_new_from_native(&name, name_len), FALSE, NULL); gret = g_socket_bind(gsock, g_socket_address_new_from_native(&name, name_len), FALSE, NULL);
if(gret == FALSE) { if (gret == FALSE) {
g_slice_free (NiceSocket, sock); g_slice_free (NiceSocket, sock);
g_socket_close(gsock, NULL); g_socket_close (gsock, NULL);
g_object_unref(gsock); g_object_unref (gsock);
return NULL; return NULL;
} }
gaddr = g_socket_get_local_address(gsock, NULL); gaddr = g_socket_get_local_address(gsock, NULL);
if(gaddr == NULL) { if(gaddr == NULL) {
g_slice_free (NiceSocket, sock); g_slice_free (NiceSocket, sock);
g_socket_close(gsock, NULL); g_socket_close (gsock, NULL);
g_object_unref(gsock); g_object_unref (gsock);
return NULL; return NULL;
} }
...@@ -125,8 +126,7 @@ nice_udp_bsd_socket_new (NiceAddress *addr) ...@@ -125,8 +126,7 @@ nice_udp_bsd_socket_new (NiceAddress *addr)
g_object_unref(gaddr); g_object_unref(gaddr);
nice_address_set_from_sockaddr (&sock->addr, (struct sockaddr *)&name); nice_address_set_from_sockaddr (&sock->addr, (struct sockaddr *)&name);
//sock->gsock = gsock;
sock->fileno = gsock; sock->fileno = gsock;
sock->send = socket_send; sock->send = socket_send;
sock->recv = socket_recv; sock->recv = socket_recv;
...@@ -139,9 +139,9 @@ nice_udp_bsd_socket_new (NiceAddress *addr) ...@@ -139,9 +139,9 @@ nice_udp_bsd_socket_new (NiceAddress *addr)
static void static void
socket_close (NiceSocket *sock) socket_close (NiceSocket *sock)
{ {
if(sock->fileno) { if (sock->fileno) {
g_socket_close(sock->fileno, NULL); g_socket_close (sock->fileno, NULL);
g_object_unref(sock->fileno); g_object_unref (sock->fileno);
sock->fileno = NULL; sock->fileno = NULL;
} }
} }
...@@ -155,14 +155,14 @@ socket_recv (NiceSocket *sock, NiceAddress *from, guint len, gchar *buf) ...@@ -155,14 +155,14 @@ socket_recv (NiceSocket *sock, NiceAddress *from, guint len, gchar *buf)
GSocketAddress *gaddr = NULL; GSocketAddress *gaddr = NULL;
GError *gerr = NULL; GError *gerr = NULL;
recvd = g_socket_receive_from(sock->fileno, &gaddr, buf, len, NULL, &gerr); recvd = g_socket_receive_from (sock->fileno, &gaddr, buf, len, NULL, &gerr);
if (recvd < 0) { if (recvd < 0) {
if(g_error_matches(gerr, G_IO_ERROR, G_IO_ERROR_WOULD_BLOCK) if (g_error_matches(gerr, G_IO_ERROR, G_IO_ERROR_WOULD_BLOCK)
|| g_error_matches(gerr, G_IO_ERROR, G_IO_ERROR_FAILED)) || g_error_matches(gerr, G_IO_ERROR, G_IO_ERROR_FAILED))
recvd = 0; recvd = 0;
g_error_free(gerr); g_error_free (gerr);
} }
if (recvd > 0) { if (recvd > 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