From: Mark Wooding Date: Tue, 2 Jun 2020 10:11:01 +0000 (+0100) Subject: bin/disorder-notify: Keep the log connection alive by sending bytes back. X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~mdw/git/profile/commitdiff_plain/50d7331db4130b568d309e0bb087fa1b71213a67 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. --- 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";