[libmessage-passing-perl] 01/12: Fix bug where FileTail only reads a single line
Jonas Smedegaard
js at alioth.debian.org
Mon Sep 30 08:38:20 UTC 2013
This is an automated email from the git hooks/post-receive script.
js pushed a commit to branch master
in repository libmessage-passing-perl.
commit 38c16361a3ad8a83dfed6e1231967a9e80c5566b
Author: Mike Tonks <michael.tonks at headforwards.com>
Date: Tue Jul 23 15:55:00 2013 +0100
Fix bug where FileTail only reads a single line
---
lib/Message/Passing/Input/FileTail.pm | 73 ++++++++++++++++++++++-----------
1 file changed, 49 insertions(+), 24 deletions(-)
diff --git a/lib/Message/Passing/Input/FileTail.pm b/lib/Message/Passing/Input/FileTail.pm
index 6f12581..d18e5a3 100644
--- a/lib/Message/Passing/Input/FileTail.pm
+++ b/lib/Message/Passing/Input/FileTail.pm
@@ -49,34 +49,59 @@ sub _build_tail_handle {
die("Cannot open filename '" . $self->filename . "'") unless -r $self->filename;
my $child_pid = open(my $r, "-|", "tail", "-F", $self->filename)
|| die "can't fork: $!";
- my $hdl;
- my $_handle_error = sub {
- my $i; $i = AnyEvent->idle(cb => sub {
- undef $i;
- $hdl->destroy;
- undef $hdl;
- close($r);
- $self->_tail_handle;
- });
- };
+
+ my $cv = AnyEvent->condvar;
+
+ my $hdl;
$hdl = AnyEvent::Handle->new(
fh => $r,
- on_error => $_handle_error,
- on_eof => $_handle_error,
+ on_read => sub {
+ my ($hdl) = @_;
+ $hdl->push_read(
+ line => sub {
+ my ($hdl, $line, $eof) = @_;
+ $self->_emit_line($line);
+ }
+ );
+ },
+ on_eof => sub {
+ # must re-initialize the original handle to continue tailing.
+ # the timer isn't necessary, but just to be a good citizen.
+ my $t;
+ $t = AnyEvent->timer( after => 1, cb => sub {
+ $t = undef;
+ $hdl = init_tailer( $r);
+ });
+ },
+ #on_error => $_handle_error,
);
- $hdl->push_read(line => sub {
- my ($hdl, $input) = @_;
- if (!defined $input) {
- $self->_clear_tail_handle;
- my $i; $i = AnyEvent->idle(cb => sub {
- undef $i;
- close($r);
- $self->_tail_handle;
- });
- return;
+}
+
+sub _init_tailer {
+ my ($self, $fh) = @_;
+
+ my $hdl;
+ $hdl = AnyEvent::Handle->new(
+ fh => $fh,
+ on_read => sub {
+ my ($hdl) = @_;
+ $hdl->push_read(
+ line => sub {
+ my ($hdl, $line, $eof) = @_;
+ $self->_emit_line($line);
}
- $self->_emit_line($input);
- });
+ );
+ },
+ on_eof => sub {
+ # must re-initialize the original handle to continue tailing.
+ # the timer isn't necessary, but just to be a good citizen.
+ my $t;
+ $t = AnyEvent->timer( after => 1, cb => sub {
+ $t = undef;
+ $self->_init_tailer($fh);
+ });
+ },
+ );
}
sub BUILD {
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-perl/packages/libmessage-passing-perl.git
More information about the Pkg-perl-cvs-commits
mailing list