From 2101e27b937893aa427d8693161966e3673b887e Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Mon, 24 Jun 2019 02:52:33 +0000 Subject: ds: hoist out do_read from NNTP and HTTP Both NNTP and HTTP have common needs and we can factor out some common code to make dealing with IO::Socket::SSL easier. --- lib/PublicInbox/DS.pm | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'lib/PublicInbox/DS.pm') diff --git a/lib/PublicInbox/DS.pm b/lib/PublicInbox/DS.pm index 9811405b..8735e888 100644 --- a/lib/PublicInbox/DS.pm +++ b/lib/PublicInbox/DS.pm @@ -473,6 +473,15 @@ next_buf: 1; # all done } +sub do_read ($$$$) { + my ($self, $rbuf, $len, $off) = @_; + my $r = sysread($self->{sock}, $$rbuf, $len, $off); + return ($r == 0 ? $self->close : $r) if defined $r; + # common for clients to break connections without warning, + # would be too noisy to log here: + $! == EAGAIN ? $self->watch_in1 : $self->close; +} + sub write_in_full ($$$$) { my ($fh, $bref, $len, $off) = @_; my $rv = 0; @@ -583,6 +592,7 @@ sub watch ($$) { $KQueue->EV_SET($fd, EVFILT_READ(), kq_flag(EPOLLIN, $ev)); $KQueue->EV_SET($fd, EVFILT_WRITE(), kq_flag(EPOLLOUT, $ev)); } + 0; } sub watch_in1 ($) { watch($_[0], EPOLLIN | EPOLLONESHOT) } -- cgit v1.2.3-24-ge0c7