diff options
author | Eric Wong <e@80x24.org> | 2019-06-24 02:52:38 +0000 |
---|---|---|
committer | Eric Wong <e@80x24.org> | 2019-06-24 05:26:26 +0000 |
commit | b70cf61f0c1f70621b88fe6420083a576d47f19f (patch) | |
tree | 88b4cd6fb40e983d7b9a536456067e42b7d890ba /lib/PublicInbox/DS.pm | |
parent | 93fc0336d39ba3ef07b479877e64371f07c86eab (diff) | |
download | public-inbox-b70cf61f0c1f70621b88fe6420083a576d47f19f.tar.gz |
It kinda, barely works, and I'm most happy I got it working without any modifications to the main NNTP::event_step callback thanks to the DS->write(CODE) support we inherited from Danga::Socket.
Diffstat (limited to 'lib/PublicInbox/DS.pm')
-rw-r--r-- | lib/PublicInbox/DS.pm | 28 |
1 files changed, 26 insertions, 2 deletions
diff --git a/lib/PublicInbox/DS.pm b/lib/PublicInbox/DS.pm index 1a1ef7d3..044b991c 100644 --- a/lib/PublicInbox/DS.pm +++ b/lib/PublicInbox/DS.pm @@ -465,7 +465,11 @@ next_buf: } } else { #($ref eq 'CODE') { shift @$wbuf; + my $before = scalar(@$wbuf); $bref->($self); + + # bref may be enqueueing more CODE to call (see accept_tls_step) + return 0 if (scalar(@$wbuf) > $before); } } # while @$wbuf @@ -479,7 +483,14 @@ sub do_read ($$$$) { 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; + if (ref($self) eq 'IO::Socket::SSL') { + my $ev = PublicInbox::TLS::epollbit() or return $self->close; + watch($self, $ev | EPOLLONESHOT); + } elsif ($! == EAGAIN) { + watch($self, EPOLLIN | EPOLLONESHOT); + } else { + $self->close; + } } # drop the socket if we hit unrecoverable errors on our system which @@ -566,7 +577,7 @@ sub msg_more ($$) { my $self = $_[0]; my $sock = $self->{sock} or return 1; - if (MSG_MORE && !$self->{wbuf}) { + if (MSG_MORE && !$self->{wbuf} && ref($sock) ne 'IO::Socket::SSL') { my $n = send($sock, $_[1], MSG_MORE); if (defined $n) { my $nlen = bytes::length($_[1]) - $n; @@ -597,6 +608,19 @@ sub watch ($$) { sub watch_in1 ($) { watch($_[0], EPOLLIN | EPOLLONESHOT) } +# return true if complete, false if incomplete (or failure) +sub accept_tls_step ($) { + my ($self) = @_; + my $sock = $self->{sock} or return; + return 1 if $sock->accept_SSL; + return $self->close if $! != EAGAIN; + if (my $ev = PublicInbox::TLS::epollbit()) { + unshift @{$self->{wbuf} ||= []}, \&accept_tls_step; + return watch($self, $ev | EPOLLONESHOT); + } + drop($self, 'BUG? EAGAIN but '.PublicInbox::TLS::err()); +} + package PublicInbox::DS::Timer; # [$abs_float_firetime, $coderef]; sub cancel { |