daily pastebin goal


a guest Apr 16th, 2018 47 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. =item How do I read data until the other side closes the connection?
  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}>:
  8.    $handle->on_read (sub { });
  9.    $handle->on_eof (undef);
  10.    $handle->on_error (sub {
  11.       my $data = delete $_[0]{rbuf};
  12.    });
  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.
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand