Guest User

Untitled

a guest
Apr 16th, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.61 KB | None | 0 0
  1. =item How do I read data until the other side closes the connection?
  2.  
  3. If you just want to read your data into a perl scalar, the easiest way
  4. to achieve this is by setting an C<on_read> callback that does nothing,
  5. clearing the C<on_eof> callback and in the C<on_error> callback, the data
  6. will be in C<$_[0]{rbuf}>:
  7.  
  8. $handle->on_read (sub { });
  9. $handle->on_eof (undef);
  10. $handle->on_error (sub {
  11. my $data = delete $_[0]{rbuf};
  12. });
  13.  
  14. The reason to use C<on_error> is that TCP connections, due to latencies
  15. and packets loss, might get closed quite violently with an error, when in
  16. fact, all data has been received.
Add Comment
Please, Sign In to add comment