telepathy-gabble: debug build: set TCP_NODELAY on sockets that Wocky creates
Jonny Lamb
jonny at kemper.freedesktop.org
Mon Sep 17 07:08:28 PDT 2012
Module: telepathy-gabble
Branch: master
Commit: 1420fafea0aa209323f6245afd3f3d9f6452fe8d
URL: http://cgit.freedesktop.org/telepathy/telepathy-gabble/commit/?id=1420fafea0aa209323f6245afd3f3d9f6452fe8d
Author: Jonny Lamb <jonny.lamb at collabora.co.uk>
Date: Fri May 4 11:34:22 2012 +0100
debug build: set TCP_NODELAY on sockets that Wocky creates
Signed-off-by: Jonny Lamb <jonny.lamb at collabora.co.uk>
---
tests/twisted/main-debug.c | 52 ++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 52 insertions(+), 0 deletions(-)
diff --git a/tests/twisted/main-debug.c b/tests/twisted/main-debug.c
index 8916667..7fa0e20 100644
--- a/tests/twisted/main-debug.c
+++ b/tests/twisted/main-debug.c
@@ -19,6 +19,13 @@
#include <stdlib.h>
+#include <glib.h>
+
+#ifdef G_OS_UNIX
+#include <netinet/in.h>
+#include <netinet/tcp.h>
+#endif
+
#include "gabble.h"
#include "connection.h"
#include "vcard-manager.h"
@@ -34,12 +41,43 @@
#include <dbus/dbus.h>
+#ifdef G_OS_UNIX
+static gboolean
+connection_established_cb (GSignalInvocationHint *ihint,
+ guint n_param_values,
+ const GValue *param_values,
+ gpointer user_data)
+{
+ GSocketConnection *conn;
+ GSocket *sock;
+ gint flag, ret, fd;
+
+ conn = g_value_get_object (param_values + 1);
+ sock = g_socket_connection_get_socket (conn);
+
+ flag = 1;
+
+ fd = g_socket_get_fd (sock);
+ ret = setsockopt (fd, IPPROTO_TCP, TCP_NODELAY,
+ (const char *) &flag, sizeof (flag));
+
+ if (ret == -1)
+ /* not the worst thing ever. */
+ g_print ("Couldn't setsockopt(TCP_NODELAY) on the connection; ain't so bad.\n");
+
+ return TRUE;
+}
+#endif
+
int
main (int argc,
char **argv)
{
int ret = 1;
GResolver *kludged;
+#ifdef G_OS_UNIX
+ gpointer cls;
+#endif
gabble_init ();
@@ -72,12 +110,26 @@ main (int argc,
gtalk_file_collection_set_test_mode ();
#endif
+#ifdef G_OS_UNIX
+ /* We want to set TCP_NODELAY on the socket as soon as possible in
+ * the connector so let's use ::connection-established. We need to
+ * ref the class type as it's not loaded yet. */
+ cls = g_type_class_ref (WOCKY_TYPE_CONNECTOR);
+ g_signal_add_emission_hook (
+ g_signal_lookup ("connection-established", WOCKY_TYPE_CONNECTOR),
+ 0, connection_established_cb, NULL, NULL);
+#endif
+
ret = gabble_main (argc, argv);
/* Hack, remove the ref g_resolver has on this object, atm there is no way to
* unset a custom resolver */
g_object_unref (kludged);
+#ifdef G_OS_UNIX
+ g_type_class_unref (cls);
+#endif
+
dbus_shutdown ();
return ret;
More information about the telepathy-commits
mailing list