… | |
… | |
994 | } |
994 | } |
995 | |
995 | |
996 | while () { |
996 | while () { |
997 | # we need to use a separate tls read buffer, as we must not receive data while |
997 | # we need to use a separate tls read buffer, as we must not receive data while |
998 | # we are draining the buffer, and this can only happen with TLS. |
998 | # we are draining the buffer, and this can only happen with TLS. |
999 | $self->{rbuf} .= delete $self->{_tls_rbuf} if exists $self->{_tls_rbuf}; |
999 | $self->{rbuf} .= delete $self->{_tls_rbuf} |
|
|
1000 | if exists $self->{_tls_rbuf}; |
1000 | |
1001 | |
1001 | my $len = length $self->{rbuf}; |
1002 | my $len = length $self->{rbuf}; |
1002 | |
1003 | |
1003 | if (my $cb = shift @{ $self->{_queue} }) { |
1004 | if (my $cb = shift @{ $self->{_queue} }) { |
1004 | unless ($cb->($self)) { |
1005 | unless ($cb->($self)) { |
1005 | if ($self->{_eof}) { |
1006 | # no progress can be made |
1006 | # no progress can be made (not enough data and no data forthcoming) |
1007 | # (not enough data and no data forthcoming) |
1007 | $self->_error (Errno::EPIPE, 1), return; |
1008 | $self->_error (Errno::EPIPE, 1), return |
1008 | } |
1009 | if $self->{_eof}; |
1009 | |
1010 | |
1010 | unshift @{ $self->{_queue} }, $cb; |
1011 | unshift @{ $self->{_queue} }, $cb; |
1011 | last; |
1012 | last; |
1012 | } |
1013 | } |
1013 | } elsif ($self->{on_read}) { |
1014 | } elsif ($self->{on_read}) { |
… | |
… | |
1033 | last; |
1034 | last; |
1034 | } |
1035 | } |
1035 | } |
1036 | } |
1036 | |
1037 | |
1037 | if ($self->{_eof}) { |
1038 | if ($self->{_eof}) { |
1038 | if ($self->{on_eof}) { |
1039 | $self->{on_eof} |
1039 | $self->{on_eof}($self) |
1040 | ? $self->{on_eof}($self) |
1040 | } else { |
|
|
1041 | $self->_error (0, 1, "Unexpected end-of-file"); |
1041 | : $self->_error (0, 1, "Unexpected end-of-file"); |
1042 | } |
1042 | |
|
|
1043 | return; |
1043 | } |
1044 | } |
1044 | |
1045 | |
1045 | # may need to restart read watcher |
1046 | # may need to restart read watcher |
1046 | unless ($self->{_rw}) { |
1047 | unless ($self->{_rw}) { |
1047 | $self->start_read |
1048 | $self->start_read |