summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilip Withnall <philip@tecnocode.co.uk>2015-08-29 22:39:56 +0100
committerPhilip Withnall <philip@tecnocode.co.uk>2015-08-29 22:44:50 +0100
commit490b16f400284c5df6508fd095d592efdfbc62ae (patch)
treefd5c3e6368fa90a5bf144d5cea00315cc78a76a6
parent03d11b49b0ac14ff320192562df57898ea9f94b4 (diff)
downloadlibnice-490b16f400284c5df6508fd095d592efdfbc62ae.tar.gz
Creating TCP sockets with TCP_NODELAY option set to TRUE
Disable Nagling for underlying TCP sockets used by libnice, because they are typically used for streaming applications, or for pseudo-TCP; the bandwidth in both cases is harmed by Nagling. Based on a patch by Vadim Genkin. Maniphest Tasks: T3317 Reviewers: pwithnall Projects: #libnice Subscribers: pwithnall, vadimgenkin Differential Revision: https://phabricator.freedesktop.org/D230
-rw-r--r--socket/tcp-active.c8
-rw-r--r--socket/tcp-bsd.c8
-rw-r--r--socket/tcp-passive.c8
3 files changed, 24 insertions, 0 deletions
diff --git a/socket/tcp-active.c b/socket/tcp-active.c
index 5144678..5402806 100644
--- a/socket/tcp-active.c
+++ b/socket/tcp-active.c
@@ -50,6 +50,11 @@
#include <unistd.h>
#endif
+/* FIXME: This should be defined in gio/gnetworking.h, which we should include;
+ * but we cannot do that without refactoring.
+ * (See: https://phabricator.freedesktop.org/D230). */
+#define TCP_NODELAY 1
+
typedef struct {
GSocketAddress *local_addr;
GMainContext *context;
@@ -225,6 +230,9 @@ nice_tcp_active_socket_connect (NiceSocket *sock, NiceAddress *addr)
/* GSocket: All socket file descriptors are set to be close-on-exec. */
g_socket_set_blocking (gsock, false);
+ /* setting TCP_NODELAY to TRUE in order to avoid packet batching */
+ g_socket_set_option (gsock, IPPROTO_TCP, TCP_NODELAY, TRUE, NULL);
+
/* Allow g_socket_bind to fail */
g_socket_bind (gsock, priv->local_addr, FALSE, NULL);
diff --git a/socket/tcp-bsd.c b/socket/tcp-bsd.c
index 20dd698..c02d6e2 100644
--- a/socket/tcp-bsd.c
+++ b/socket/tcp-bsd.c
@@ -54,6 +54,11 @@
#include <unistd.h>
#endif
+/* FIXME: This should be defined in gio/gnetworking.h, which we should include;
+ * but we cannot do that without refactoring.
+ * (See: https://phabricator.freedesktop.org/D230). */
+#define TCP_NODELAY 1
+
typedef struct {
NiceAddress remote_addr;
GQueue send_queue;
@@ -168,6 +173,9 @@ nice_tcp_bsd_socket_new (GMainContext *ctx, NiceAddress *local_addr,
/* GSocket: All socket file descriptors are set to be close-on-exec. */
g_socket_set_blocking (gsock, false);
+ /* setting TCP_NODELAY to TRUE in order to avoid packet batching */
+ g_socket_set_option (gsock, IPPROTO_TCP, TCP_NODELAY, TRUE, NULL);
+
gret = g_socket_connect (gsock, gaddr, NULL, &gerr);
g_object_unref (gaddr);
diff --git a/socket/tcp-passive.c b/socket/tcp-passive.c
index 16fbe3d..131ff4b 100644
--- a/socket/tcp-passive.c
+++ b/socket/tcp-passive.c
@@ -50,6 +50,11 @@
#include <unistd.h>
#endif
+/* FIXME: This should be defined in gio/gnetworking.h, which we should include;
+ * but we cannot do that without refactoring.
+ * (See: https://phabricator.freedesktop.org/D230). */
+#define TCP_NODELAY 1
+
typedef struct {
GMainContext *context;
GHashTable *connections;
@@ -284,6 +289,9 @@ nice_tcp_passive_socket_accept (NiceSocket *sock)
/* GSocket: All socket file descriptors are set to be close-on-exec. */
g_socket_set_blocking (gsock, false);
+ /* setting TCP_NODELAY to TRUE in order to avoid packet batching */
+ g_socket_set_option (gsock, IPPROTO_TCP, TCP_NODELAY, TRUE, NULL);
+
gaddr = g_socket_get_remote_address (gsock, NULL);
if (gaddr == NULL ||
!g_socket_address_to_native (gaddr, &name.addr, sizeof (name), NULL)) {