| 1 | package Linux::Event::HTTP::_HTTP2::ClientConnection; | ||
| 2 | use v5.36; | ||
| 3 | use strict; | ||
| 4 | use warnings; | ||
| 5 | |||
| 6 | use parent 'Linux::Event::IO::Sock::Stream'; | ||
| 7 | |||
| 8 | our $VERSION = '0.003'; | ||
| 9 | |||
| 10 | sub on_data ($self, $bytes) { | ||
| 11 | my $executor = $self->{_http2_executor} | ||
| 12 | or die 'HTTP/2 client connection has no executor'; | ||
| 13 | |||
| 14 | my $ok = eval { | ||
| 15 | $executor->input($bytes); | ||
| 16 | 1; | ||
| 17 | }; | ||
| 18 | if (!$ok) { | ||
| 19 | my $error = "$@"; | ||
| 20 | $error =~ s/\s+\z//; | ||
| 21 | $executor->close( | ||
| 22 | $error ne '' ? "HTTP/2 protocol input failed: $error" | ||
| 23 | : 'HTTP/2 protocol input failed', | ||
| 24 | ) if $executor->can('close'); | ||
| 25 | delete $self->{_http2_executor}; | ||
| 26 | $self->close if !$self->is_closed; | ||
| 27 | } | ||
| 28 | return; | ||
| 29 | } | ||
| 30 | |||
| 31 | sub request ($self, @args) { | ||
| 32 | my $executor = $self->{_http2_executor} | ||
| 33 | or die 'HTTP/2 client connection has no executor'; | ||
| 34 | return $executor->request(@args); | ||
| 35 | } | ||
| 36 | |||
| 37 | sub on_close ($self) { | ||
| 38 | if (my $executor = delete $self->{_http2_executor}) { | ||
| 39 | $executor->close; | ||
| 40 | } | ||
| 41 | return; | ||
| 42 | } | ||
| 43 | |||
| 44 | 1; | ||
| 45 | |||
| 46 | __END__ |