From 79e11eea11dd561301a05c42ba824a7d352bd398 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Fri, 27 May 2016 05:59:16 +0000 Subject: git-http-backend: fix aborts for generic PSGI clone We need to avoid circular references in the generic PSGI layer, do it by abusing DESTROY. --- lib/PublicInbox/GetlineBody.pm | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 lib/PublicInbox/GetlineBody.pm (limited to 'lib/PublicInbox/GetlineBody.pm') diff --git a/lib/PublicInbox/GetlineBody.pm b/lib/PublicInbox/GetlineBody.pm new file mode 100644 index 00000000..4f8765bb --- /dev/null +++ b/lib/PublicInbox/GetlineBody.pm @@ -0,0 +1,31 @@ +# Copyright (C) 2016 all contributors +# License: AGPL-3.0+ + +# Wrap a pipe or file for PSGI streaming response bodies and calls the +# end callback when the object goes out-of-scope. +# This depends on rpipe being _blocking_ on getline. +package PublicInbox::GetlineBody; +use strict; +use warnings; + +sub new { + my ($class, $rpipe, $end, $buf) = @_; + bless { rpipe => $rpipe, end => $end, buf => $buf }, $class; +} + +sub DESTROY { $_[0]->close } + +sub getline { + my ($self) = @_; + my $buf = delete $self->{buf}; + defined $buf ? $buf : $self->{rpipe}->getline; +} + +sub close { + my ($self) = @_; + delete $self->{rpipe}; + my $end = delete $self->{end} or return; + $end->(); +} + +1; -- cgit v1.2.3-24-ge0c7