From 403b8cb313a2122fee8a490a99be9aef9038a74e Mon Sep 17 00:00:00 2001 From: Alexander Sulfrian Date: Wed, 28 Oct 2015 21:27:39 +0100 Subject: stats: Serialized data could be more than one line We need to buffer the incomming data and process is at whole if we receive an EOF. Storabel::freeze can produce multiple lines. --- stats.pl | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/stats.pl b/stats.pl index 4d54e35..19a1b5f 100755 --- a/stats.pl +++ b/stats.pl @@ -25,21 +25,20 @@ sub my_die { tcp_connect "unix/", $socket, sub { my ($fh) = @_ or my_die("Unable to connect to socket: $!");; + my $data; my $h; $h = new AnyEvent::Handle fh => $fh, on_eof => sub { - $h->destroy; - my_die('Connection closed.'); + # read stats data + my $stats = Storable::thaw($data); + + print "OK | ham=$stats->{ham};;;0 spam=$stats->{spam};;;0 block=$stats->{block};;;0\n"; + $cv->send; }, on_read => sub { $h->push_read(line => sub { my ($h, $line) = @_; - - # read stats data - my $stats = Storable::thaw($line); - - print "OK | ham=$stats->{ham};;;0 spam=$stats->{spam};;;0 block=$stats->{block};;;0\n"; - $cv->send; + $data .= "$line\n"; }); }; }; -- cgit v1.2.3-1-g7c22