From 50d7331db4130b568d309e0bb087fa1b71213a67 Mon Sep 17 00:00:00 2001 From: Mark Wooding Date: Tue, 2 Jun 2020 11:11:01 +0100 Subject: [PATCH] bin/disorder-notify: Keep the log connection alive by sending bytes back. This was, if it's not already clear, the main objective to the `select'-based log loop. --- bin/disorder-notify | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/bin/disorder-notify b/bin/disorder-notify index b632ef4..092d255 100755 --- a/bin/disorder-notify +++ b/bin/disorder-notify @@ -220,18 +220,24 @@ sub watch_and_notify0 ($) { } if (!$sk_log) { $loss = "EOF from server"; last WATCH; } - select my $rdout = $rdin, undef, undef, undef; - READ: for (;;) { - my ($b, $n); - eval { $n = sysread $sk_log, $b, 4096; }; - if ($@ && $@->errno == EAGAIN) { last READ; } - elsif ($@) { $loss = "error from read: " . $@->errno; last WATCH; } - elsif (!$n) { close $sk_log; $sk_log = undef; } - else { $buffer .= $b; } - } + my $nfd = select my $rdout = $rdin, undef, undef, 60; + if (!$nfd) { + eval { print $sk_log "."; flush $sk_log; }; + if ($@) { $loss = "error from write: " . $@->errno; last WATCH; } + @lines = (); + } else { + READ: for (;;) { + my ($b, $n); + eval { $n = sysread $sk_log, $b, 4096; }; + if ($@ && $@->errno == EAGAIN) { last READ; } + elsif ($@) { $loss = "error from read: " . $@->errno; last WATCH; } + elsif (!$n) { close $sk_log; $sk_log = undef; } + else { $buffer .= $b; } + } - @lines = split /\n/, $buffer, -1; - $buffer = pop @lines; + @lines = split /\n/, $buffer, -1; + $buffer = pop @lines; + } } notify "$TITLE state", "Lost connection: $loss"; -- 2.11.0