From 595854982a59f369ab605794f05c046c86253468 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Mon, 24 Jun 2019 02:52:42 +0000 Subject: nntp: call SSL_shutdown in normal cases This is in accordance with TLS standards and will be needed to support session caching/reuse in the future. However, we don't issue shutdown(2) since we know not to inadvertantly share our sockets with other processes. --- lib/PublicInbox/DS.pm | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'lib/PublicInbox/DS.pm') diff --git a/lib/PublicInbox/DS.pm b/lib/PublicInbox/DS.pm index 2c886b4e..2aa9e3d2 100644 --- a/lib/PublicInbox/DS.pm +++ b/lib/PublicInbox/DS.pm @@ -621,6 +621,30 @@ sub accept_tls_step ($) { drop($self, 'BUG? EAGAIN but '.PublicInbox::TLS::err()); } +sub shutdn_tls_step ($) { + my ($self) = @_; + my $sock = $self->{sock} or return; + return $self->close if $sock->stop_SSL(SSL_fast_shutdown => 1); + return $self->close if $! != EAGAIN; + if (my $ev = PublicInbox::TLS::epollbit()) { + unshift @{$self->{wbuf} ||= []}, \&shutdn_tls_step; + return watch($self, $ev | EPOLLONESHOT); + } + drop($self, 'BUG? EAGAIN but '.PublicInbox::TLS::err()); +} + +# don't bother with shutdown($sock, 2), we don't fork+exec w/o CLOEXEC +# or fork w/o exec, so no inadvertant socket sharing +sub shutdn ($) { + my ($self) = @_; + my $sock = $self->{sock} or return; + if (ref($sock) eq 'IO::Socket::SSL') { + shutdn_tls_step($self); + } else { + $self->close; + } +} + package PublicInbox::DS::Timer; # [$abs_float_firetime, $coderef]; sub cancel { -- cgit v1.2.3-24-ge0c7