Bug#306422: gtetrinet: [patch] fixes network message latency

Julien Plissonneau Duquene Julien Plissonneau Duquene <debbug2005@julien.plissonneau.duquene.net>, 306422@bugs.debian.org
Tue, 26 Apr 2005 14:44:54 +0200


--TB36FDmn/VVEgNH/
Content-Type: text/plain; charset=iso-8859-1
Content-Disposition: inline
Content-Transfer-Encoding: 8bit

Package: gtetrinet
Version: 0.7.8-1
X-Debbugs-CC: jordi@sindominio.net, bocata@panete.net
Severity: normal
Tags: patch

Hello,

Attached is a small patch that fixes network message latency with
gtetrinet. Actually the network channel is unbuffered and the lowest
message sending function uses two writes to push every message to the
network, which result in two TCP packets being sent for every message.
The handicap can clearly be seen at the start of games (typically your
opponent has already dropped 1 or 2 blocks when your first one becomes
available).

With this patch gtetrinet's latency matches that of other clients.

Regards,

-- 
Julien Plissonneau Duqučne


--TB36FDmn/VVEgNH/
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename=patch

--- client.c.orig	2005-04-26 12:50:43.000000000 +0200
+++ client.c	2005-04-26 12:56:15.000000000 +0200
@@ -431,12 +431,14 @@
 
 int client_sendmsg (char *str)
 {
-    char c = 0xFF;
+    gchar *buf;
     GError *error = NULL;
     
-    g_io_channel_write_chars (io_channel, str, -1, NULL, &error);
-    g_io_channel_write_chars (io_channel, &c, 1, NULL, &error);
+    buf = g_strdup(str);
+    buf[strlen(str)] = 0xFF;
+    g_io_channel_write_chars (io_channel, buf, strlen(str)+1, NULL, &error);
     g_io_channel_flush (io_channel, &error);
+    g_free(buf);
 
 #ifdef DEBUG
     printf ("> %s\n", str);

--TB36FDmn/VVEgNH/--