… | |
… | |
37 | |
37 | |
38 | my $buf; |
38 | my $buf; |
39 | |
39 | |
40 | $self->{w} = AnyEvent->io (fh => $self->{fh}, poll => 'r', cb => sub { |
40 | $self->{w} = AnyEvent->io (fh => $self->{fh}, poll => 'r', cb => sub { |
41 | if (sysread $self->{fh}, $buf, 16384, length $buf) { |
41 | if (sysread $self->{fh}, $buf, 16384, length $buf) { |
42 | if (2 <= length $buf) { |
42 | for (;;) { |
|
|
43 | last unless 2 <= length $buf; |
43 | my $len = unpack "n", $buf; |
44 | my $len = unpack "n", $buf; |
44 | if ($len + 2 <= length $buf) { |
45 | last unless $len + 2 <= length $buf; |
|
|
46 | |
45 | substr $buf, 0, 2, ""; |
47 | substr $buf, 0, 2, ""; |
46 | $self->feed (substr $buf, 0, $len, ""); |
48 | $self->feed (substr $buf, 0, $len, ""); |
47 | } |
|
|
48 | } |
49 | } |
49 | } else { |
50 | } else { |
50 | delete $self->{w}; |
51 | delete $self->{w}; |
51 | close $self->{fh}; |
52 | close $self->{fh}; |
52 | } |
53 | } |