This is an automated email from the git hooks/post-receive script.

git pushed a commit to branch tymux-10-quiet-head
in repository terminology.

View the commit online.

commit 81091b54e485be336c9a600f59cd649b52b7f8ad
Author: Cedric BAIL <[email protected]>
AuthorDate: Thu Nov 19 09:41:13 2026 -0600

    termd_tymux: stop streaming the scrollback to clients
    
    Clients now read the scrollback from the memfd backlog pages, so the
    TSRV_MSG_BACKLOG stream (and BACKLOG_RESET, which resynced a client that
    fell behind on it) has no reader left. Remove it with the attach-time
    snapshot and the per-client flow control that went with it, and retire
    message types 12 and 13.
    
    The daemon's own termpty only has to merge wrapped rows and resize its
    terminal, so it keeps TERMD_TYMUX_PTY_BACKLOG (256) entries instead of
    the full scrollback; the page store keeps the 10000 lines. A line
    wrapped over more than 256 rows still merges, as it only ever extends
    the newest entry: tytest backlog_hook_long_wrap covers it.
    
    tests/tymux.py checked the streamed messages; it now checks that none of
    the retired types is sent. The busy-queue live test queued its backlog
    behind the page with a scrollback flood, and now uses title messages.
    
    tybenchd sees no throughput change: the benchmark attaches no client,
    and the backlog hook already fed the pages before this commit. Median of
    5 runs, 1 to 1000000, release build, 3 invocations each:
    
      before: 0.374 s, 0.375 s, 0.377 s (18.4, 18.3, 18.3 MB/s)
      after:  0.363 s, 0.361 s, 0.369 s (19.0, 19.1, 18.6 MB/s)
    
    Daemon memory after `seq 1 10000` with one client attached (tymux new on
    a pty, private XDG_RUNTIME_DIR, 3 runs within a few kB of each other):
    
      before: VmRSS 16750 kB (RssAnon 3480 kB)
      after:  VmRSS 15490 kB (RssAnon 2252 kB)
---
 man/tymux.1            |  21 +--
 src/bin/termd_tymux.c  | 317 +-------------------------------------------
 src/bin/termd_tymux.h  |   9 +-
 src/bin/termpty.c      |  73 +++++++++++
 src/bin/termsrv.c      |  82 ------------
 src/bin/termsrv.h      |  32 +----
 src/bin/tytest.c       |   2 +-
 src/bin/tytest_tymux.c |  25 ++--
 src/bin/unit_tests.h   |   2 +-
 tests/tymux.py         | 348 ++-----------------------------------------------
 10 files changed, 117 insertions(+), 794 deletions(-)

diff --git a/man/tymux.1 b/man/tymux.1
index 7f323845..38c1f81a 100644
--- a/man/tymux.1
+++ b/man/tymux.1
@@ -194,20 +194,13 @@ or
 closes the terminal, like any other terminal whose shell exited.
 .SH BUGS
 A terminal a native hand-off (see \fBNATIVE HAND\-OFF\fP) attaches to has
-its own scrollback: the daemon streams every line as it scrolls off its
-screen, and the terminal saves it the same way it would save a line of its
-own, so scrolling, selection, search and the miniview work on it like on
-any other terminal. Hyperlinks in that backlog are not: the daemon does
-not send the link targets, only inert text. A terminal that attaches gets
-the most recent lines of the daemon's backlog: at most 2000 lines, a line
-that wrapped counting once, and about 256 KiB of them, so fewer when they are
-wide. The newest lines are taken first and the rest stop at the first one
-that does not fit, so a line larger than that is not sent, nor are the ones
-before it. A client too slow to keep up
-with a burst of new lines is not dropped for falling behind on scrollback
-alone: it stops receiving it for a while, then has it replaced with a
-fresh copy once it catches up, so its scrollback stays consistent at the
-cost of a short gap in what got attached to it in the meantime. The
+its own scrollback: it reads the lines the daemon keeps in shared memory,
+mapping only the part it shows, so scrolling, selection, search and the
+miniview work on it like on any other terminal. Hyperlinks in that backlog
+are not: the daemon does not send the link targets, only inert text. A
+terminal that attaches keeps as many of the lines the daemon holds as its
+own scrollback setting allows, the oldest ones being dropped first; the
+daemon itself holds up to 10000. The
 inline proxy still has no scrollback of its own.
 .PP
 When proxied (not natively handed off), the attached terminal is also
diff --git a/src/bin/termd_tymux.c b/src/bin/termd_tymux.c
index 0ed2a8e7..3714a823 100644
--- a/src/bin/termd_tymux.c
+++ b/src/bin/termd_tymux.c
@@ -12,7 +12,6 @@
 #include "termpty.h"
 #include "termsrv.h"
 #include "termd_backlog.h"
-#include "backlog.h"
 #include "termd_tymux.h"
 
 _Static_assert(sizeof(Termcell) == sizeof(TermSrvCell),
@@ -32,14 +31,6 @@ typedef enum
  * clients. */
 #define CLIENT_OUT_MAX (1 << 20)
 
-/* Above this many queued bytes, a client stops receiving TSRV_MSG_BACKLOG
- * (NOTIFY and screen updates keep flowing) instead of being dropped: a
- * scrollback flood is not worth losing a healthy but slow reader over. */
-#define CLIENT_BACKLOG_HIGH (CLIENT_OUT_MAX / 4)
-/* Once the queue drains back under this, the client gets a
- * TSRV_MSG_BACKLOG_RESET and a fresh snapshot to replace what it missed. */
-#define CLIENT_BACKLOG_LOW  (CLIENT_OUT_MAX / 16)
-
 typedef struct
 {
    size_t offset;
@@ -59,9 +50,6 @@ typedef struct
    TermSrvReader     reader;
    Eina_Bool         dispatching : 1;
    Eina_Bool         dead : 1;
-   /* TSRV_MSG_BACKLOG is being withheld until the queue drains, see
-    * CLIENT_BACKLOG_HIGH/LOW */
-   Eina_Bool         backlog_out_of_sync : 1;
    /* ids of the backlog pages this client holds, as uintptr_t, ascending */
    Eina_List        *held_pages;
    /* memfds waiting to go out with their message, in order: each rides on
@@ -80,9 +68,6 @@ struct tag_TermDTymux
    /* clients paused by a hijack, most recent first */
    Eina_List        *paused;
    Ecore_Animator   *notify_anim;
-   /* lines that entered the backlog since the last TSRV_MSG_BACKLOG
-    * broadcast, packed with termsrv_backlog_line_append() */
-   Eina_Binbuf      *backlog_pending;
    Eina_Bool         dirty : 1;
    Eina_Bool         backlog_append_failed : 1;
 };
@@ -116,34 +101,8 @@ _screen_flush(TermDTymux *td)
 static void _client_del(Client *client);
 static void _client_pages_prune(Client *client);
 static void _client_free(Client *client);
-static void _client_attach_backlog_send(Client *client);
 static Eina_Bool _client_send(Client *client, TermSrvMsgType type,
                               const void *payload, uint32_t size);
-static void _backlog_pending_flush(TermDTymux *td);
-
-/* Called once a client's queue has drained back under CLIENT_BACKLOG_LOW
- * after it had fallen behind on TSRV_MSG_BACKLOG: tell it to discard its
- * now-stale shadow backlog and give it a fresh snapshot, the same one a
- * client attaching right now would get. */
-static void
-_client_backlog_resync(Client *client)
-{
-   /* Lines still sitting in td->backlog_pending are already part of
-    * ty->back, so the snapshot below would include them: flush them to the
-    * other clients first (client is still marked out of sync, so
-    * _broadcast_backlog() skips it here) or the next ordinary flush would
-    * hand them to this client a second time, right after its snapshot. */
-   _backlog_pending_flush(client->td);
-   client->backlog_out_of_sync = EINA_FALSE;
-   if (!_client_send(client, TSRV_MSG_BACKLOG_RESET, NULL, 0))
-     {
-        _client_del(client);
-        return;
-     }
-   if (client->dead)
-     return;
-   _client_attach_backlog_send(client);
-}
 
 /* For a client that missed a message, when it cannot be deleted right away:
  * its fd handler sees the end of file and deletes it. */
@@ -233,9 +192,6 @@ _client_flush(Client *client)
    ecore_main_fd_handler_active_set(client->handler,
                                     ECORE_FD_READ | (len ? ECORE_FD_WRITE : 0));
 
-   if (client->backlog_out_of_sync && len <= CLIENT_BACKLOG_LOW)
-     _client_backlog_resync(client);
-
    return EINA_TRUE;
 }
 
@@ -274,55 +230,6 @@ _broadcast(TermDTymux *td, TermSrvMsgType type,
      }
 }
 
-/* Like _broadcast(), but for TSRV_MSG_BACKLOG: a client whose queue is
- * already past CLIENT_BACKLOG_HIGH is not sent this message (and not
- * dropped for it), and is instead marked out of sync so that
- * _client_flush() resyncs it with a TSRV_MSG_BACKLOG_RESET and a fresh
- * snapshot once it catches up. NOTIFY and screen updates go through the
- * ordinary _broadcast() and are unaffected. */
-static void
-_broadcast_backlog(TermDTymux *td, const void *payload, uint32_t size)
-{
-   Eina_List *l, *l_next;
-   Client *client;
-
-   EINA_LIST_FOREACH_SAFE(td->clients, l, l_next, client)
-     {
-        if (client->role == CLIENT_PENDING)
-          continue;
-        if (client->backlog_out_of_sync)
-          continue;
-        if (eina_binbuf_length_get(client->out) > CLIENT_BACKLOG_HIGH)
-          {
-             client->backlog_out_of_sync = EINA_TRUE;
-             continue;
-          }
-        if (!_client_send(client, TSRV_MSG_BACKLOG, payload, size))
-          _client_del(client);
-     }
-}
-
-/* Broadcast whatever backlog lines piled up since the last flush, then
- * empty the accumulator. Lines are pushed in already-framed
- * (cols + cells) form by _cb_pty_backlog(), one TSRV_MSG_BACKLOG message
- * for the lot: _cb_pty_backlog() never lets it grow past the payload cap,
- * so it always fits in one message. */
-static void
-_backlog_pending_flush(TermDTymux *td)
-{
-   size_t len;
-
-   if (!td->backlog_pending)
-     return;
-   len = eina_binbuf_length_get(td->backlog_pending);
-   if (len == 0)
-     return;
-   _broadcast_backlog(td, eina_binbuf_string_get(td->backlog_pending),
-                      (uint32_t)len);
-   eina_binbuf_free(td->backlog_pending);
-   td->backlog_pending = NULL;
-}
-
 static void
 _flush_and_notify(TermDTymux *td)
 {
@@ -345,10 +252,6 @@ _flush_and_notify(TermDTymux *td)
         td->notify_anim = NULL;
      }
 
-   /* lines that scrolled off before this frame so a client applies them to
-    * its backlog before the frame that no longer shows them */
-   _backlog_pending_flush(td);
-
    notify.first_page_id = termd_backlog_first_id(td->backlog);
    notify.page_count = termd_backlog_count(td->backlog);
    EINA_LIST_FOREACH(td->clients, l, client)
@@ -384,45 +287,15 @@ _cb_pty_change(void *data)
      td->notify_anim = ecore_animator_add(_cb_notify_anim, td);
 }
 
-/* Whether any client has attached (or is still waiting for its own
- * TSRV_MSG_BACKLOG snapshot flow -- CLIENT_PENDING clients get theirs from
- * _client_attach_backlog_send(), not from here) so that keeping
- * td->backlog_pending fed is worth the cost. With no client at all, as in
- * the default tybenchd workload, _cb_pty_backlog() should cost nothing. */
-static Eina_Bool
-_td_has_backlog_client(TermDTymux *td)
-{
-   Eina_List *l;
-   Client *client;
-
-   EINA_LIST_FOREACH(td->clients, l, client)
-     if (client->role != CLIENT_PENDING)
-       return EINA_TRUE;
-   return EINA_FALSE;
-}
-
 /* Called synchronously whenever a line permanently enters the daemon's own
  * backlog (termpty_text_save_top()), i.e. potentially many times between
- * two animator ticks under a flood such as `seq 1 1000000`. It always
- * goes to the page store, which clients map; then, for the clients that
- * still read the stream, pack it
- * straight into td->backlog_pending (no intermediate copy: CELLS is
- * exactly TermSrvCell laid out, per the _Static_assert above), flushing
- * what is there first if the line would not fit in one TSRV_MSG_BACKLOG
- * payload, so the accumulator never grows past TERMSRV_MAX_MSG_PAYLOAD and
- * a flood cannot build up an unbounded amount of memory or a single
- * oversized send. Older lines that get flushed this way are still
- * recoverable: they are already in ty->back and get sent to any client
- * attaching afterwards (see _client_attach_backlog_send()). W is at most
- * ty->w (see termpty_backlog_hook_set()'s contract), itself capped to
- * TERMSRV_MAX_COLS by _client_resize(), so it always fits in one message
- * on its own. */
+ * two animator ticks under a flood such as `seq 1 1000000`. The page store
+ * is the scrollback clients map; the daemon's termpty only keeps
+ * TERMD_TYMUX_PTY_BACKLOG entries, to merge wrapped rows. */
 static void
 _cb_pty_backlog(void *data, Termpty *ty EINA_UNUSED, const Termcell *cells, ssize_t w, Eina_Bool extends)
 {
    TermDTymux *td = data;
-   uint32_t off, cols = (uint32_t)w;
-   uint64_t need = sizeof(cols) + (uint64_t)cols * sizeof(TermSrvCell);
 
    if (!termd_backlog_append(td->backlog, cells, w, extends) &&
        !td->backlog_append_failed)
@@ -430,30 +303,6 @@ _cb_pty_backlog(void *data, Termpty *ty EINA_UNUSED, const Termcell *cells, ssiz
         ERR("cannot store the backlog in pages");
         td->backlog_append_failed = EINA_TRUE;
      }
-   if (!_td_has_backlog_client(td))
-     return;
-
-   if (!td->backlog_pending)
-     td->backlog_pending = eina_binbuf_new();
-   if (!td->backlog_pending)
-     return;
-
-   off = (uint32_t)eina_binbuf_length_get(td->backlog_pending);
-   if (need > TERMSRV_MAX_MSG_PAYLOAD)
-     return;
-   if (off + need > TERMSRV_MAX_MSG_PAYLOAD)
-     {
-        _backlog_pending_flush(td);
-        td->backlog_pending = eina_binbuf_new();
-        if (!td->backlog_pending)
-          return;
-     }
-
-   eina_binbuf_append_length(td->backlog_pending,
-                             (const unsigned char *)&cols, sizeof(cols));
-   eina_binbuf_append_length(td->backlog_pending,
-                             (const unsigned char *)cells,
-                             cols * sizeof(TermSrvCell));
 }
 
 static void
@@ -505,150 +354,6 @@ termd_tymux_signal_exit(TermDTymux *td, int exit_code)
    _exit_broadcast(td, exit_code);
 }
 
-/* Where the chunk of a backlog entry that starts at from ends. An entry is
- * as wide as the line it holds was before it wrapped, so it can be wider
- * than TERMSRV_MAX_COLS, which one wire line cannot carry. The client trims
- * the empty cells off the end of what it receives, with the same
- * termpty_line_length() used here, and that would take the wrap flag of the
- * chunk with them: the chunk ends on a cell that is not empty. */
-static uint32_t
-_backlog_chunk_end(const TermSrvCell *cells, uint32_t from, uint32_t total)
-{
-   ssize_t used;
-
-   if (total - from <= TERMSRV_MAX_COLS)
-     return total;
-   used = termpty_line_length((const Termcell *)(cells + from),
-                              TERMSRV_MAX_COLS);
-   return from + (used > 0 ? used : TERMSRV_MAX_COLS);
-}
-
-/* Bytes the entry takes on the wire, in as many chunks as it needs */
-static uint64_t
-_backlog_entry_size(const Termsave *ts)
-{
-   const TermSrvCell *cells = (const TermSrvCell *)ts->cells;
-   uint64_t size = 0;
-   uint32_t from = 0, end;
-
-   do
-     {
-        end = _backlog_chunk_end(cells, from, ts->w);
-        size += sizeof(uint32_t) + (uint64_t)(end - from) * sizeof(*cells);
-        from = end;
-     }
-   while (from < ts->w);
-   return size;
-}
-
-/* Send the daemon's existing backlog to a client that just attached, oldest
- * first, so it can rebuild the same scrollback a client that had been there
- * all along would have. At most TERMD_TYMUX_ATTACH_BACKLOG_MAX lines, and no
- * more than CLIENT_BACKLOG_HIGH bytes: the most recent ones are kept. A
- * snapshot that filled the queue would get the client dropped before it
- * showed anything. The lines are packed into as few TSRV_MSG_BACKLOG
- * messages as the payload cap allows, and one wider than TERMSRV_MAX_COLS
- * is cut into chunks, all but the last flagged as wrapping onto the next so
- * that the client's backlog joins them again, the way it joins the rows a
- * long line wrapped over. Called synchronously while handling ATTACH, so it
- * always lands before any NOTIFY: the daemon does not send frames from
- * inside message handling, only from the animator. */
-static void
-_client_attach_backlog_send(Client *client)
-{
-   Termpty *ty = client->td->pty;
-   ssize_t length = termpty_backlog_length(ty);
-   ssize_t start, first = 0;
-   int64_t budget;
-   Eina_Binbuf *buf;
-
-   if (length <= 0)
-     return;
-   /* length counts screen rows, which is at least the number of entries
-    * and can pass the size of the ring, where BACKLOG_ROW_GET() wraps */
-   if (length > (ssize_t)ty->backsize - 1)
-     length = (ssize_t)ty->backsize - 1;
-   if (length > TERMD_TYMUX_ATTACH_BACKLOG_MAX)
-     length = TERMD_TYMUX_ATTACH_BACKLOG_MAX;
-
-   /* the headers of the messages the lines are packed into */
-   budget = (int64_t)CLIENT_BACKLOG_HIGH -
-      (int64_t)eina_binbuf_length_get(client->out) -
-      64 * (int64_t)sizeof(TermSrvMsgHdr);
-   /* backlog_y counts back from 1 (most recent line) */
-   for (start = 1; start <= length; start++)
-     {
-        const Termsave *ts = BACKLOG_ROW_GET(ty, start);
-        uint64_t size;
-
-        if (!ts->cells)
-          continue;
-        size = _backlog_entry_size(ts);
-        if (budget < 0 || size > (uint64_t)budget)
-          break;
-        budget -= size;
-        first = start;
-     }
-   if (first == 0)
-     return;
-
-   buf = eina_binbuf_new();
-   if (!buf)
-     return;
-
-   for (start = first; start >= 1; start--)
-     {
-        const Termsave *ts = BACKLOG_ROW_GET(ty, start);
-        const TermSrvCell *cells = (const TermSrvCell *)ts->cells;
-        uint32_t from = 0, end;
-
-        if (!cells)
-          continue;
-        do
-          {
-             unsigned char stage[sizeof(uint32_t) +
-                                 TERMSRV_MAX_COLS * sizeof(TermSrvCell)];
-             uint32_t stage_off = 0;
-             size_t cur = eina_binbuf_length_get(buf);
-
-             end = _backlog_chunk_end(cells, from, ts->w);
-             if (termsrv_backlog_line_append(stage, sizeof(stage), &stage_off,
-                                             end - from, cells + from) < 0)
-               break;
-             if (end < ts->w)
-               {
-                  unsigned char *last = stage + stage_off - sizeof(*cells);
-                  TermSrvCell cell;
-
-                  memcpy(&cell, last, sizeof(cell));
-                  cell.att.autowrapped = 1;
-                  memcpy(last, &cell, sizeof(cell));
-               }
-             if (cur + stage_off > TERMSRV_MAX_MSG_PAYLOAD)
-               {
-                  if (!_client_send(client, TSRV_MSG_BACKLOG,
-                                    eina_binbuf_string_get(buf),
-                                    (uint32_t)cur))
-                    {
-                       _client_del(client);
-                       eina_binbuf_free(buf);
-                       return;
-                    }
-                  eina_binbuf_reset(buf);
-               }
-             eina_binbuf_append_length(buf, stage, stage_off);
-             from = end;
-          }
-        while (from < ts->w);
-     }
-   if (eina_binbuf_length_get(buf) > 0 &&
-       !_client_send(client, TSRV_MSG_BACKLOG,
-                     eina_binbuf_string_get(buf),
-                     (uint32_t)eina_binbuf_length_get(buf)))
-     _client_del(client);
-   eina_binbuf_free(buf);
-}
-
 static void
 _client_attach(Client *client, TermSrvAttachMode mode)
 {
@@ -665,16 +370,6 @@ _client_attach(Client *client, TermSrvAttachMode mode)
         _client_del(client);
         return;
      }
-   /* Lines still sitting in td->backlog_pending are already part of
-    * ty->back, so the snapshot below would include them: flush them to the
-    * already-attached clients first (client is still CLIENT_PENDING, so
-    * _broadcast_backlog() skips it) or it would get them twice, once in
-    * its snapshot and again in the next flush. */
-   _backlog_pending_flush(td);
-   _client_attach_backlog_send(client);
-   if (client->dead)
-     return;
-
    switch (mode)
      {
       case TSRV_ATTACH_HIJACK:
@@ -1024,10 +719,10 @@ termd_tymux_new(const char *name, const char *cmd)
    td->config = calloc(1, sizeof(Config));
    if (!td->config)
      goto err;
-   td->config->scrollback = 10000;
+   td->config->scrollback = TERMD_TYMUX_PTY_BACKLOG;
    td->config->term_type = TERM_TYPE_XTERM_256COLOR;
 
-   td->backlog = termd_backlog_new(name, td->config->scrollback);
+   td->backlog = termd_backlog_new(name, TERMD_TYMUX_SCROLLBACK);
    if (!td->backlog)
      goto err;
 
@@ -1084,8 +779,6 @@ termd_tymux_free(TermDTymux *td)
      return;
    if (td->notify_anim)
      ecore_animator_del(td->notify_anim);
-   if (td->backlog_pending)
-     eina_binbuf_free(td->backlog_pending);
    EINA_LIST_FREE(td->clients, client)
      {
         struct timeval timeout = { .tv_sec = 0, .tv_usec = 200 * 1000 };
diff --git a/src/bin/termd_tymux.h b/src/bin/termd_tymux.h
index e23a30b9..20a3d2eb 100644
--- a/src/bin/termd_tymux.h
+++ b/src/bin/termd_tymux.h
@@ -3,9 +3,12 @@
 
 typedef struct tag_TermDTymux TermDTymux;
 
-/* Most backlog lines sent to a client attaching mid-stream, bounding how
- * much a slow client is asked to catch up on. */
-#define TERMD_TYMUX_ATTACH_BACKLOG_MAX 2000
+/* Lines of scrollback the page store keeps for the clients. */
+#define TERMD_TYMUX_SCROLLBACK 10000
+
+/* Entries the daemon's own termpty keeps: enough to merge wrapped rows and
+ * to resize its terminal, the pages being the scrollback. */
+#define TERMD_TYMUX_PTY_BACKLOG 256
 
 /* Start the shell (cmd, or the user's shell if NULL) on a new pty whose
  * screen is published in shared memory. The main loop is quit when the
diff --git a/src/bin/termpty.c b/src/bin/termpty.c
index 1f8b7ded..3b845c31 100644
--- a/src/bin/termpty.c
+++ b/src/bin/termpty.c
@@ -5093,6 +5093,79 @@ _ty_backlog_hook_replay(void *data, Termpty *ty EINA_UNUSED, const Termcell *cel
    termpty_text_save_top(dst, (Termcell *)cells, w);
 }
 
+typedef struct
+{
+   int new_entries;
+   int extensions;
+} Ty_Backlog_Extends_Count;
+
+static void
+_ty_backlog_hook_count_extends(void *data, Termpty *ty EINA_UNUSED, const Termcell *cells EINA_UNUSED, ssize_t w EINA_UNUSED, Eina_Bool extends)
+{
+   Ty_Backlog_Extends_Count *count = data;
+
+   if (extends)
+     count->extensions++;
+   else
+     count->new_entries++;
+}
+
+/* Test: a logical line wrapped over more rows than the backlog ring has
+ * entries still merges into one entry, the hook reporting every row after
+ * the first as an extension. The daemon of tymux keeps a ring of 256
+ * entries and relies on this to feed its page store. */
+int
+tytest_backlog_hook_long_wrap(void)
+{
+   enum { RING = 256, WRAPPED_ROWS = 300 };
+   Termpty ty_storage, *ty = &ty_storage;
+   Termcell cells[10];
+   Ty_Backlog_Extends_Count count = { 0, 0 };
+   const Termsave *ts;
+   int i, j;
+
+   _ty_test_init(ty, 10, 5);
+   termpty_backlog_size_set(ty, RING);
+   termpty_backlog_hook_set(ty, _ty_backlog_hook_count_extends, &count);
+
+   memset(cells, 0, sizeof(cells));
+   for (j = 0; j < 10; j++)
+     cells[j].codepoint = 'a';
+   for (i = 0; i < RING + 20; i++)
+     termpty_text_save_top(ty, cells, 10);
+   assert(count.new_entries == RING + 20 && count.extensions == 0);
+
+   count.new_entries = 0;
+   for (i = 0; i < WRAPPED_ROWS; i++)
+     {
+        for (j = 0; j < 10; j++)
+          cells[j].codepoint = 'a' + (i % 26);
+        cells[9].att.autowrapped = (i < WRAPPED_ROWS - 1);
+        termpty_text_save_top(ty, cells, 10);
+     }
+   assert(count.new_entries == 1);
+   assert(count.extensions == WRAPPED_ROWS - 1);
+
+   ts = BACKLOG_ROW_GET(ty, 1);
+   assert(ts->w == 10 * WRAPPED_ROWS);
+   assert(ts->cells[0].codepoint == 'a');
+   assert(ts->cells[10 * (WRAPPED_ROWS - 1)].codepoint ==
+          (unsigned int)('a' + ((WRAPPED_ROWS - 1) % 26)));
+   assert(!ts->cells[ts->w - 1].att.autowrapped);
+
+   /* nothing merges into the line once it ended */
+   for (j = 0; j < 10; j++)
+     cells[j].codepoint = 'z';
+   termpty_text_save_top(ty, cells, 10);
+   assert(count.new_entries == 2);
+   assert(count.extensions == WRAPPED_ROWS - 1);
+   assert(BACKLOG_ROW_GET(ty, 2)->w == 10 * WRAPPED_ROWS);
+
+   termpty_backlog_hook_set(ty, NULL, NULL);
+   _ty_test_shutdown(ty);
+   return 0;
+}
+
 int
 tytest_backlog_hook_wrap_replay(void)
 {
diff --git a/src/bin/termsrv.c b/src/bin/termsrv.c
index 84faa1ef..fc62fdf5 100644
--- a/src/bin/termsrv.c
+++ b/src/bin/termsrv.c
@@ -454,44 +454,6 @@ termsrv_msg_send(int fd, TermSrvMsgType type,
    return termsrv_msg_send_fd(fd, type, payload, size, -1);
 }
 
-int
-termsrv_backlog_line_append(void *buf, uint32_t bufsz, uint32_t *off,
-                            uint32_t cols, const TermSrvCell *cells)
-{
-   uint64_t need = (uint64_t)sizeof(cols) + (uint64_t)cols * sizeof(*cells);
-
-   if (*off > bufsz || need > (uint64_t)(bufsz - *off))
-     return -1;
-   memcpy((unsigned char *)buf + *off, &cols, sizeof(cols));
-   *off += sizeof(cols);
-   memcpy((unsigned char *)buf + *off, cells, cols * sizeof(*cells));
-   *off += cols * sizeof(*cells);
-   return 0;
-}
-
-int
-termsrv_backlog_line_next(const void *payload, uint32_t size,
-                          uint32_t *off, uint32_t *cols_out,
-                          const TermSrvCell **cells_out)
-{
-   uint32_t cols;
-   uint64_t need;
-
-   if (*off == size)
-     return 0;
-   if (*off > size || size - *off < sizeof(cols))
-     return -1;
-   memcpy(&cols, (const unsigned char *)payload + *off, sizeof(cols));
-   need = (uint64_t)sizeof(cols) + (uint64_t)cols * sizeof(TermSrvCell);
-   if (need > (uint64_t)(size - *off))
-     return -1;
-   *cols_out = cols;
-   *cells_out = (const TermSrvCell *)
-      ((const unsigned char *)payload + *off + sizeof(cols));
-   *off += (uint32_t)need;
-   return 1;
-}
-
 int
 termsrv_backlog_map_page_append(void *buf, uint32_t bufsz, uint32_t *off,
                                 uint32_t page_id, uint32_t num_entries,
@@ -1628,50 +1590,6 @@ tytest_termsrv_cell_layout(void)
    return 0;
 }
 
-int
-tytest_termsrv_backlog_line(void)
-{
-   unsigned char buf[256];
-   TermSrvCell line1[3], line2[2];
-   uint32_t off = 0, cols;
-   const TermSrvCell *cells;
-
-   memset(line1, 0, sizeof(line1));
-   line1[0].codepoint = 'a';
-   line1[1].codepoint = 'b';
-   line1[2].codepoint = 'c';
-   memset(line2, 0, sizeof(line2));
-   line2[0].codepoint = 'd';
-   line2[1].codepoint = 'e';
-
-   assert(termsrv_backlog_line_append(buf, sizeof(buf), &off, 3, line1) == 0);
-   assert(termsrv_backlog_line_append(buf, sizeof(buf), &off, 2, line2) == 0);
-
-   off = 0;
-   assert(termsrv_backlog_line_next(buf, sizeof(buf), &off, &cols, &cells) == 1);
-   assert(cols == 3);
-   assert(cells[0].codepoint == 'a' && cells[2].codepoint == 'c');
-
-   assert(termsrv_backlog_line_next(buf, off + (uint32_t)sizeof(cols) +
-                                    2 * (uint32_t)sizeof(TermSrvCell),
-                                    &off, &cols, &cells) == 1);
-   assert(cols == 2);
-   assert(cells[1].codepoint == 'e');
-
-   assert(termsrv_backlog_line_next(buf, off, &off, &cols, &cells) == 0);
-
-   /* too small a buffer to fit the line */
-   off = sizeof(buf) - 4;
-   assert(termsrv_backlog_line_append(buf, sizeof(buf), &off, 3, line1) < 0);
-
-   /* truncated payload: the header claims more cells than are there */
-   off = 0;
-   assert(termsrv_backlog_line_append(buf, sizeof(buf), &off, 3, line1) == 0);
-   assert(termsrv_backlog_line_next(buf, off - 1, &off, &cols, &cells) < 0);
-
-   return 0;
-}
-
 int
 tytest_termsrv_backlog_page_fd(void)
 {
diff --git a/src/bin/termsrv.h b/src/bin/termsrv.h
index 56551694..34cdb7af 100644
--- a/src/bin/termsrv.h
+++ b/src/bin/termsrv.h
@@ -135,18 +135,7 @@ typedef enum
    TSRV_MSG_EXIT     = 9,  /* daemon: TermSrvMsgExit, the shell exited */
    TSRV_MSG_PAUSE    = 10, /* daemon: another client took over the input */
    TSRV_MSG_RESUME   = 11, /* daemon: the client that took over left */
-   /* daemon: one or more lines that entered the backlog, packed with
-    * termsrv_backlog_line_append() and read back with
-    * termsrv_backlog_line_next(); sent for lines already in the backlog
-    * right after ATTACHED, and again for every line that scrolls off the
-    * screen afterwards. */
-   TSRV_MSG_BACKLOG  = 12,
-   /* daemon: this client fell behind on TSRV_MSG_BACKLOG and stopped
-    * receiving it for a while; its shadow backlog is stale and must be
-    * discarded before the fresh snapshot that immediately follows, in one
-    * or more TSRV_MSG_BACKLOG messages, is applied. NOTIFY and screen
-    * updates were not affected and need no such reset. */
-   TSRV_MSG_BACKLOG_RESET = 13,
+   /* 12 and 13 are retired: the backlog used to be streamed in them */
    /* client: ask for a backlog page, TermSrvMsgBacklogPageId. An unknown
     * or evicted page gets no reply. */
    TSRV_MSG_BACKLOG_PAGE_REQ = 14,
@@ -409,25 +398,6 @@ int termsrv_send_attached(int fd, int shm_fd,
 int termsrv_recv_attached(int fd, int *shm_fd_out,
                           TermSrvMsgAttached *attached_out);
 
-/* Backlog lines are packed one after another in a TSRV_MSG_BACKLOG
- * payload, each as a uint32_t cell count followed by that many
- * TermSrvCell, so several lines can share one message within the
- * TERMSRV_MAX_MSG_PAYLOAD cap.
- *
- * Append one line to buf (of bufsz bytes, *off already used). Returns 0 on
- * success, -1 if it does not fit. */
-int termsrv_backlog_line_append(void *buf, uint32_t bufsz, uint32_t *off,
-                                uint32_t cols, const TermSrvCell *cells);
-
-/* Take the next line out of a TSRV_MSG_BACKLOG payload of size bytes,
- * starting at *off (0 on the first call), and advance *off past it.
- * Returns 1 and sets cols_out and cells_out (pointing inside payload) when a
- * line was read, 0 once *off reaches size, -1 if the payload is
- * malformed. */
-int termsrv_backlog_line_next(const void *payload, uint32_t size,
-                              uint32_t *off, uint32_t *cols_out,
-                              const TermSrvCell **cells_out);
-
 /* The payload of TSRV_MSG_BACKLOG_MAP is a TermSrvMsgBacklogMapReq, then per
  * page its page_id and num_entries as uint32_t, followed by num_entries
  * uint32_t widths in cells.
diff --git a/src/bin/tytest.c b/src/bin/tytest.c
index 8632cea5..d2afad8b 100644
--- a/src/bin/tytest.c
+++ b/src/bin/tytest.c
@@ -39,6 +39,7 @@ static struct {
        { "write_hook", tytest_write_hook},
        { "backlog_hook", tytest_backlog_hook},
        { "backlog_hook_wrap_replay", tytest_backlog_hook_wrap_replay},
+       { "backlog_hook_long_wrap", tytest_backlog_hook_long_wrap},
        { "backlog_wide_entry_rows", tytest_backlog_wide_entry_rows},
        { "backlog_external", tytest_backlog_external},
        { "backlog_window", tytest_backlog_window},
@@ -176,7 +177,6 @@ static struct {
        { "termsrv_shm_seqlock", tytest_termsrv_shm_seqlock},
        { "termsrv_attached", tytest_termsrv_attached},
        { "termsrv_cell_layout", tytest_termsrv_cell_layout},
-       { "termsrv_backlog_line", tytest_termsrv_backlog_line},
        { "termsrv_backlog_page_fd", tytest_termsrv_backlog_page_fd},
        { "termsrv_backlog_map", tytest_termsrv_backlog_map},
        { "termd_backlog_pages", tytest_termd_backlog_pages},
diff --git a/src/bin/tytest_tymux.c b/src/bin/tytest_tymux.c
index 8b94eb0c..d3e52ea0 100644
--- a/src/bin/tytest_tymux.c
+++ b/src/bin/tytest_tymux.c
@@ -375,8 +375,6 @@ tytest_tymux_daemon_memfds(TermTymux *ts, const char *prefix)
 
 #define SESSION "ty-live"
 #define SEQ_CHECKED 2990
-/* termd_tymux.c sends at most TERMD_TYMUX_ATTACH_BACKLOG_MAX rows on
- * attach, and the rows after the checked run take some of them */
 #define REATTACH_RUN_MIN 1900
 #define WIDE_MIN 5000
 #define SCREEN_ROWS 10
@@ -780,13 +778,13 @@ _never_done(void *data EINA_UNUSED)
    return EINA_FALSE;
 }
 
-/* The flood stays under the scrollback of the daemon (10000 entries), so
- * that the page asked for is not evicted while the client is not reading. A
- * full socket, and a queue past CLIENT_BACKLOG_HIGH, are still reached: the
- * 4000 lines of the first flood are some 2 MB of backlog messages. The 3000
- * lines of the second one only add screen updates behind the page.
- *
- * A client that does not read while a flood goes by has a full socket and
+/* The shell sets a title of 4000 characters COUNT times, each one a message
+ * to every client. */
+#define TITLE_FLOOD(COUNT) \
+   "T=$(printf '%04000d' 0); for i in $(seq 1 " #COUNT "); do " \
+   "printf '\\033]0;%s\\007' \"$T\"; done\n"
+
+/* A client that does not read while a flood goes by has a full socket and
  * a growing queue in the daemon: a page it asks for then must wait in that
  * queue, with its memfd, and still arrive when the client reads again. */
 static int
@@ -817,14 +815,15 @@ _live_pages_busy_body(void)
 
    /* fd is not read from now on, until the flood is over */
    assert(tytest_tymux_type(ts, ty, "seq 1 4000\n"));
+   assert(tytest_tymux_type(ts, ty, TITLE_FLOOD(100)));
    tytest_tymux_wait(_never_done, NULL, 3.0);
    req.page_id = attached.first_page_id;
    assert(termsrv_msg_send(fd, TSRV_MSG_BACKLOG_PAGE_REQ, &req,
                            sizeof(req)) == 0);
-   /* more screen updates, which queue behind the page in the daemon: more
-    * than the 4096 bytes a read takes, so that a read that picks up the
-    * page memfd ends well after the page message */
-   assert(tytest_tymux_type(ts, ty, "seq 1 3000\n"));
+   /* more messages, which queue behind the page in the daemon: more than
+    * the 4096 bytes a read takes, so that a read that picks up the page
+    * memfd ends well after the page message */
+   assert(tytest_tymux_type(ts, ty, TITLE_FLOOD(10)));
    tytest_tymux_wait(_never_done, NULL, 3.0);
 
    for (;;)
diff --git a/src/bin/unit_tests.h b/src/bin/unit_tests.h
index ad22e8f1..c4dc2956 100644
--- a/src/bin/unit_tests.h
+++ b/src/bin/unit_tests.h
@@ -9,6 +9,7 @@ int tytest_dummy(void);
 int tytest_write_hook(void);
 int tytest_backlog_hook(void);
 int tytest_backlog_hook_wrap_replay(void);
+int tytest_backlog_hook_long_wrap(void);
 int tytest_backlog_wide_entry_rows(void);
 int tytest_backlog_external(void);
 int tytest_backlog_window(void);
@@ -131,7 +132,6 @@ int tytest_termsrv_msg_send_full(void);
 int tytest_termsrv_shm_seqlock(void);
 int tytest_termsrv_attached(void);
 int tytest_termsrv_cell_layout(void);
-int tytest_termsrv_backlog_line(void);
 int tytest_termsrv_backlog_page_fd(void);
 int tytest_termsrv_backlog_map(void);
 int tytest_termd_backlog_pages(void);
diff --git a/tests/tymux.py b/tests/tymux.py
index dd8bc336..25796fd1 100644
--- a/tests/tymux.py
+++ b/tests/tymux.py
@@ -348,8 +348,10 @@ def main():
     a.send("echo alive-$((6+6))\r")
     check(a.expect("alive-12"), "the primary still works")
 
-    # a native client's backlog: a raw socket plays the wire protocol
-    # directly since the CLI proxy has no scrollback of its own to check.
+    # the scrollback reaches a native client through the backlog pages (see
+    # tytest_tymux_live_*), not as messages: a raw socket sees none of the
+    # retired types 12 and 13, neither on attach nor for lines that scroll
+    # off afterwards.
     NAME4 = "k%d" % os.getpid()
     b = Client(["new", NAME4])
     check(b.expect("$ "), "backlog: new session shell prompt shown")
@@ -385,352 +387,24 @@ def main():
                     return None
                 buf.extend(data)
 
-    # sizeof(TermSrvCell): a uint32_t codepoint and a 12 byte TermSrvAtt
-    cell_size = 16
-
-    def backlog_lines(payload):
-        lines = []
-        off = 0
-        while off < len(payload):
-            (cols,) = struct.unpack_from("=I", payload, off)
-            off += 4
-            cells = []
-            for _ in range(cols):
-                cp = struct.unpack_from("<I", payload, off)[0]
-                cells.append(cp)
-                off += cell_size
-            lines.append("".join(chr(c) if c else " " for c in cells)
-                        .rstrip())
-        return lines
-
-    # the shell is idle after the seq: nothing dirties the screen, so no
-    # NOTIFY is due yet. Only the backlog sent right after ATTACHED can
-    # show up in this window.
+    b.send("seq 101 200\r")
+    b.idle(1)
     buf = bytearray()
-    seen_before_notify = []
+    retired = []
     end = time.time() + 2
     while time.time() < end:
         got = recv_msg(raw, buf, timeout=max(0.1, end - time.time()))
         if got is None:
             break
-        mtype, payload = got
-        if mtype == 12:  # BACKLOG
-            seen_before_notify += backlog_lines(payload)
-    check("1" in seen_before_notify,
-          "backlog: the existing backlog is sent to a client on attach")
-
-    # Do not assert on b's own rendered screen here: with two clients
-    # attached, exactly how many of its frames termio's diff renderer
-    # coalesces before drawing is not deterministic enough to match
-    # against literal digits with a scroll this fast. The daemon's
-    # backlog stream, read below, is the ground truth for this test.
-    b.send("seq 101 200\r")
-    b.idle(1)
-    seen_after_attach = []
-    end = time.time() + 5
-    while time.time() < end and "101" not in seen_after_attach:
-        got = recv_msg(raw, buf, timeout=max(0.1, end - time.time()))
-        if got is None:
-            break
-        mtype, payload = got
-        if mtype == 12:
-            seen_after_attach += backlog_lines(payload)
-    check("101" in seen_after_attach,
-          "backlog: lines that scroll off after attach are streamed too")
-
-    # a flood needs several BACKLOG messages: the line that does not fit
-    # in the one being filled starts the next, it is not lost
-    b.send("seq 201 3200\r")
-    streamed = set()
-    end = time.time() + 20
-    while time.time() < end and "3170" not in streamed:
-        got = recv_msg(raw, buf, timeout=max(0.1, end - time.time()))
-        if got is None:
-            break
-        mtype, payload = got
-        if mtype == 12:
-            streamed.update(backlog_lines(payload))
-    missing = [n for n in range(201, 3171) if str(n) not in streamed]
-    check(not missing,
-          "backlog: no line is lost between two streamed messages"
-          " (%d missing, first %s)" % (len(missing), missing[:3]))
+        if got[0] in (12, 13):
+            retired.append(got[0])
+    check(not retired,
+          "backlog: no retired streaming message is sent (%s)" % retired)
 
     raw.close()
     tymux("kill", NAME4)
     check(b.wait() is not None, "backlog: killing the session detaches it")
 
-    def attach_raw(name):
-        """attach read-only, returns (socket, bytes received so far)"""
-        sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
-        sock.connect(os.path.join(XDG, "terminology", "tymux", name + ".sock"))
-        sock.send(struct.pack("=IIB", 1, 1, 2))
-        msg, fds, _, _ = socket.recv_fds(sock, 28, 1)
-        for fd in fds:
-            os.close(fd)
-        return sock
-
-    def snapshot_read(sock, duration=3):
-        """the BACKLOG lines received for duration seconds, as lists of
-        (codepoint, autowrapped), and whether the daemon hung up"""
-        lines = []
-        buf = bytearray()
-        end = time.time() + duration
-        while time.time() < end:
-            ready, _, _ = select.select([sock], [], [], 0.2)
-            if not ready:
-                continue
-            data = "" << 20)
-            if not data:
-                return lines, True
-            buf.extend(data)
-            while len(buf) >= 8:
-                mtype, msize = struct.unpack_from("=II", bytes(buf))
-                if len(buf) < 8 + msize:
-                    break
-                payload = bytes(buf[8:8 + msize])
-                del buf[:8 + msize]
-                if mtype != 12:
-                    continue
-                off = 0
-                while off < len(payload):
-                    (cols,) = struct.unpack_from("=I", payload, off)
-                    off += 4
-                    cells = []
-                    for _ in range(cols):
-                        cp = struct.unpack_from("<I", payload, off)[0]
-                        # autowrapped is the first flag of the third word of
-                        # the attributes, after the codepoint
-                        wrapped = payload[off + 12] & 1
-                        cells.append((cp, wrapped))
-                        off += cell_size
-                    lines.append(cells)
-        return lines, False
-
-    # a client attaching gets the 2000 most recent lines, not all of them
-    NAME9 = "n%d" % os.getpid()
-    nr = Client(["new", NAME9])
-    check(nr.expect("$ "), "narrow: new session shell prompt shown")
-    nr.send("seq 1 5000; echo done-$((1+2))\r")
-    check(nr.expect("done-3"), "narrow: the lines are printed")
-    nr.idle(1)
-    narrow = attach_raw(NAME9)
-    lines, hung_up = snapshot_read(narrow)
-    numbers = [int(t) for t in ("".join(chr(c) if c else " " for c, _ in l)
-                                .strip() for l in lines) if t.isdigit()]
-    check(not hung_up and len(numbers) == 2000,
-          "narrow: the snapshot holds 2000 lines (%d)" % len(numbers))
-    check(numbers == list(range(numbers[0], numbers[0] + len(numbers)))
-          and numbers[-1] >= 4950,
-          "narrow: they are the most recent ones, in order (last: %d)"
-          % (numbers[-1] if numbers else 0))
-    narrow.close()
-    tymux("kill", NAME9)
-    nr.wait()
-
-    # a full backlog of wide lines does not fit the output queue of a client:
-    # attaching to it must not get the client dropped, and it gets the most
-    # recent lines
-    NAME7 = "w%d" % os.getpid()
-    w = Client(["new", NAME7], rows=24, cols=200)
-    check(w.expect("$ "), "wide: new session shell prompt shown")
-    w.send("seq 1 3000 | awk '{printf \"%s %0176d\\n\", $1, 0}';"
-           " echo done-$((1+2))\r")
-    check(w.expect("done-3"), "wide: the lines are printed")
-    w.idle(2)
-    wide = attach_raw(NAME7)
-    lines, hung_up = snapshot_read(wide)
-    check(not hung_up, "wide: a client attaching to a wide backlog is not"
-          " dropped")
-    numbers = [int("".join(chr(c) for c, _ in l).split()[0])
-               for l in lines if l and l[0][0]]
-    check(len(numbers) > 0 and max(numbers) >= 2950,
-          "wide: the snapshot ends with the most recent lines")
-    check(numbers == sorted(numbers) and len(numbers) < 3000,
-          "wide: the snapshot is in order and limited")
-    check(NAME7 in tymux("list").stdout, "wide: the session is still running")
-    wide.close()
-    tymux("kill", NAME7)
-    w.wait()
-
-    # a line wrapped over more rows than TERMSRV_MAX_COLS cells is sent in
-    # chunks that the client joins through the autowrapped flag
-    NAME8 = "l%d" % os.getpid()
-    lg = Client(["new", NAME8])
-    check(lg.expect("$ "), "long line: new session shell prompt shown")
-    lg.send("printf '%03000d\\n' 0; seq 1 60; echo done-$((1+2))\r")
-    check(lg.expect("done-3"), "long line: the line is printed")
-    lg.idle(1)
-    longline = attach_raw(NAME8)
-    lines, hung_up = snapshot_read(longline)
-    texts = ["".join(chr(c) if c else " " for c, _ in l) for l in lines]
-    chunks = [i for i, l in enumerate(lines) if l and set(c for c, _ in l)
-              == {ord("0")}]
-    joined = "".join(texts[i] for i in chunks)
-    check(joined == "0" * 3000,
-          "long line: the 3000 cells arrive (%d)" % len(joined))
-    check(len(chunks) >= 2 and all(lines[i][-1][1] for i in chunks[:-1])
-          and not lines[chunks[-1]][-1][1],
-          "long line: the chunks are flagged to be joined again")
-    longline.close()
-    tymux("kill", NAME8)
-    lg.wait()
-
-    # a chunk cannot end on a concealed cell: the client would trim it, and
-    # with it the flag that joins the next chunk. 79 columns so that the
-    # concealed cell, the 1920th of the line, is not at the end of a row,
-    # where it would be trimmed before being saved.
-    NAME10 = "c%d" % os.getpid()
-    cn = Client(["new", NAME10], cols=79)
-    check(cn.expect("$ "), "concealed: new session shell prompt shown")
-    cn.send("printf '%01919d\\033[8mX\\033[0m%01080d\\n' 0 0; seq 1 60;"
-            " echo done-$((1+2))\r")
-    check(cn.expect("done-3"), "concealed: the line is printed")
-    cn.idle(1)
-    concealed = attach_raw(NAME10)
-    lines, hung_up = snapshot_read(concealed)
-    wide_lines = [l for l in lines if len(l) > 100]
-    check(len(wide_lines) == 2 and len(wide_lines[0]) == 1919
-          and wide_lines[0][-1][1] and len(wide_lines[1]) == 1081,
-          "concealed: the first chunk ends before the concealed cell (%s)"
-          % [len(l) for l in wide_lines])
-    concealed.close()
-    tymux("kill", NAME10)
-    cn.wait()
-
-    # a client attaching in the middle of a flood must not see any backlog
-    # line twice: the daemon has to flush what it was about to broadcast to
-    # the already-attached clients before it snapshots ty->back for the new
-    # one, or the snapshot and the next flush both carry the same lines.
-    NAME5 = "p%d" % os.getpid()
-    c = Client(["new", NAME5])
-    check(c.expect("$ "), "dup: new session shell prompt shown")
-    path5 = os.path.join(XDG, "terminology", "tymux", NAME5 + ".sock")
-    c.send("seq 1 60000\r")
-    raw2 = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
-    raw2.connect(path5)
-    raw2.send(struct.pack("=IIB", 1, 1, 2))  # ATTACH, readonly, no idle:
-    # racing the flood is the point of this test.
-    msg, fds, _, _ = socket.recv_fds(raw2, 28, 1)
-    for fd in fds:
-        os.close(fd)
-    check(len(msg) == 28 and struct.unpack_from("=II", msg)[0] == 2,
-          "dup: ATTACHED is received during a flood")
-
-    # A resync (see the slow-reader test below) legitimately re-sends a
-    # window of lines the client already had: it always starts with a
-    # TSRV_MSG_BACKLOG_RESET, on which a real client discards its shadow
-    # backlog before applying what follows. Do the same here, or a resync
-    # racing this test's own reader -- which, being Python, can lag behind
-    # a 60000-line flood enough to trigger the same flow control a slow
-    # native client would -- would look like a duplicate.
-    numbers = []
-    got_reset = False
-    buf2 = bytearray()
-    end = time.time() + 15
-    while time.time() < end:
-        got = recv_msg(raw2, buf2, timeout=max(0.1, end - time.time()))
-        if got is None:
-            break
-        mtype, payload = got
-        if mtype == 13:  # BACKLOG_RESET
-            numbers = []
-            got_reset = True
-        elif mtype == 12:
-            numbers += [int(n) for n in backlog_lines(payload)
-                       if n and n.isdigit()]
-        if numbers and numbers[-1] == 60000:
-            break
-    raw2.close()
-    check(c.expect("$ "), "dup: seq finished")
-    check(len(numbers) == len(set(numbers)),
-          "dup: no backlog line is delivered twice to a client that"
-          " attached mid-flood (%d lines, %d unique%s)"
-          % (len(numbers), len(set(numbers)),
-             ", after a resync" if got_reset else ""))
-    check(numbers == sorted(numbers),
-          "dup: backlog lines arrive in order")
-
-    tymux("kill", NAME5)
-
-    # a client too slow to keep up with a scrollback flood is not dropped
-    # for it: it stops receiving TSRV_MSG_BACKLOG for a while instead, and
-    # is caught back up with a TSRV_MSG_BACKLOG_RESET plus a fresh snapshot
-    # once its queue has drained.
-    NAME6 = "q%d" % os.getpid()
-    d = Client(["new", NAME6])
-    check(d.expect("$ "), "slow: new session shell prompt shown")
-    path6 = os.path.join(XDG, "terminology", "tymux", NAME6 + ".sock")
-    raw3 = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
-    raw3.connect(path6)
-    raw3.send(struct.pack("=IIB", 1, 1, 2))
-    msg, fds, _, _ = socket.recv_fds(raw3, 28, 1)
-    for fd in fds:
-        os.close(fd)
-    check(len(msg) == 28 and struct.unpack_from("=II", msg)[0] == 2,
-          "slow: ATTACHED is received")
-
-    resets = 0
-    tail_numbers = []
-    buf3 = bytearray()
-
-    def take(data):
-        nonlocal resets, tail_numbers
-        buf3.extend(data)
-        while len(buf3) >= 8:
-            mtype, msize = struct.unpack_from("=II", bytes(buf3))
-            if len(buf3) < 8 + msize:
-                break
-            payload = bytes(buf3[8:8 + msize])
-            del buf3[:8 + msize]
-            if mtype == 12:
-                nums = [int(n) for n in backlog_lines(payload)
-                        if n and n.isdigit()]
-                tail_numbers = (tail_numbers + nums)[-200:]
-            elif mtype == 13:  # BACKLOG_RESET
-                resets += 1
-                tail_numbers = []
-
-    d.send("seq 1 300000\r")
-    end = time.time() + 8
-    while time.time() < end:
-        # a slow reader: read whatever is queued, then back off, instead of
-        # draining the socket as fast as tymuxd can fill it.
-        time.sleep(0.3)
-        ready, _, _ = select.select([raw3], [], [], 0)
-        if not ready:
-            continue
-        data = ""
-        if not data:
-            break
-        take(data)
-    check(d.expect("$ ", timeout=30), "slow: seq finished")
-    d.send("echo alive-$((3+4))\r")
-    check(d.expect("alive-7"), "slow: the reader was not dropped")
-    # then it catches up, however long the flood took on this machine: what
-    # it was sent ends with the last lines of the flood
-    end = time.time() + 60
-    while time.time() < end and not (tail_numbers and
-                                     tail_numbers[-1] >= 299000):
-        ready, _, _ = select.select([raw3], [], [], 0.5)
-        if ready:
-            data = ""
-            if not data:
-                break
-            take(data)
-    try:
-        raw3.getpeername()
-        still_open = True
-    except OSError:
-        still_open = False
-    check(still_open, "slow: the reader's socket is still open")
-    check(tail_numbers == sorted(set(tail_numbers)),
-          "slow: the tail of the replayed backlog has no duplicates")
-    check(bool(tail_numbers) and tail_numbers[-1] >= 299000,
-          "slow: the reader's backlog ends near the end of the flood"
-          " (last seen: %d)" % (tail_numbers[-1] if tail_numbers else 0))
-    raw3.close()
-    tymux("kill", NAME6)
-
     # a client stalling in the middle of a message costs tymuxd nothing
     path = os.path.join(XDG, "terminology", "tymux", NAME + ".sock")
     pending = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.

Reply via email to