texinfo-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[no subject]


From: Gavin D. Smith
Date: Sun, 20 Mar 2022 04:55:21 -0400 (EDT)

branch: master
commit 3ecb70bbdba9cac16f79e4a0f1c047da4196de66
Author: Gavin Smith <gavinsmith0123@gmail.com>
AuthorDate: Sun Oct 20 13:57:23 2019 +0100

    split toc into packets
---
 js/infog/extension.c | 27 ++++++++++++++++++++++++++-
 1 file changed, 26 insertions(+), 1 deletion(-)

diff --git a/js/infog/extension.c b/js/infog/extension.c
index 027fbe1770..05613fbb69 100644
--- a/js/infog/extension.c
+++ b/js/infog/extension.c
@@ -292,10 +292,35 @@ void
 packetize (char *msg_type, GString *msg)
 {
   GString *s;
+  char *p, *q;
+  int try = 0; /* To check if a single record is too long for a packet. */
+
+  p = msg->str;
   s = g_string_new (NULL);
+
+next_packet:
+  g_string_truncate (s, 0);
   g_string_append (s, msg_type);
   g_string_append (s, "\n");
-  g_string_append_len (s, msg->str, msg->len);
+
+  /* Get next two lines and try to fit them in the buffer. */
+  while ((q = strchr (p, '\n')) && (q = strchr (q + 1, '\n')))
+    {
+      gsize old_len = s->len;
+      g_string_append_len (s, p, q - p + 1);
+      if (s->len > PACKET_SIZE)
+        {
+          if (try == 1)
+            break;
+          g_string_truncate (s, old_len);
+          send_datagram (s);
+          try = 1;
+          goto next_packet;
+        }
+
+      try = 0;
+      p = q + 1;
+    }
   send_datagram (s);
   g_string_free (s, TRUE);
 }



reply via email to

[Prev in Thread] Current Thread [Next in Thread]