Google-gRPC

 view release on metacpan or  search on metacpan

MANIFEST  view on Meta::CPAN

SECURITY.md
t/00-load.t
t/01-framing.t
t/02-engine-pp.t
t/03-engine-nghttp2.t
t/04-channel-stream.t
t/05-client.t
t/06-channel-pool.t
t/07-deadlines.t
t/08-retries.t
t/09-keepalive.t
t/99-pod-coverage.t
tmp/arbitrary.sh
tmp/check_env.sh
tmp/cpanm_final.log
tmp/cpanm_full.log
tmp/cpanm_install.log
tmp/cpanm_install_final.log
tmp/cpanm_tail.txt
tmp/cpanm_verb.log
tmp/demo_spanner.pl

lib/Google/gRPC/Channel.pm  view on Meta::CPAN

use Google::gRPC::Engine;
use Google::gRPC::Stream;
use Google::gRPC::Framing;
use Google::gRPC::Deadline;
use Carp qw(croak);

has target                => ( is => 'ro', required => 1 );
has auth_token            => ( is => 'ro', required => 0 );
has engine_type           => ( is => 'ro', required => 0 );
has timeout               => ( is => 'ro', required => 0 );
has keepalive_time_sec    => ( is => 'ro', required => 0 );
has keepalive_timeout_sec => ( is => 'ro', required => 0 );
has engine                => ( is => 'rw' );
has streams               => ( is => 'rw', default => sub { {} } );
has last_activity_time    => ( is => 'rw', default => sub { time() } );

sub BUILD {
    my ($self) = @_;
    my %engine_args;
    if ($self->engine_type) {
        $engine_args{engine} = $self->engine_type;
    }

lib/Google/gRPC/Channel.pm  view on Meta::CPAN

}

sub send_ping {
    my ($self, $cb) = @_;
    if ($self->engine && $self->engine->can('send_ping')) {
        $self->engine->send_ping($cb);
    }
    $self->last_activity_time(time());
}

sub check_keepalive {
    my ($self) = @_;
    return unless defined $self->keepalive_time_sec;
    my $now = time();
    if ($now - $self->last_activity_time >= $self->keepalive_time_sec) {
        $self->send_ping();
    }
}

sub check_deadlines {
    my ($self) = @_;
    for my $sid (keys %{$self->streams}) {
        my $stream = $self->streams->{$sid};
        if ($stream) {
            $stream->check_deadline();

t/09-keepalive.t  view on Meta::CPAN

use strict;
use warnings;
use Test::More tests => 2;
use Google::gRPC::Channel;

subtest 'HTTP/2 PING Keepalive Configuration' => sub {
    my $channel = Google::gRPC::Channel->new(
        target               => 'localhost:8000',
        engine_type          => 'PP',
        keepalive_time_sec   => 10,
        keepalive_timeout_sec => 5,
    );

    ok($channel, 'created channel with keepalive options');
    is($channel->keepalive_time_sec, 10, 'keepalive_time_sec set to 10');
    is($channel->keepalive_timeout_sec, 5, 'keepalive_timeout_sec set to 5');
};

subtest 'HTTP/2 PING frame emission on idle connection' => sub {
    my $channel = Google::gRPC::Channel->new(
        target               => 'localhost:8000',
        engine_type          => 'PP',
        keepalive_time_sec   => 0.01,
        keepalive_timeout_sec => 1,
    );

    # Set last_activity_time in past to simulate idle connection
    $channel->last_activity_time(time() - 2);

    my $ping_sent = 0;
    $channel->send_ping(sub {
        $ping_sent = 1;
    });

    my $out = $channel->get_output();
    ok(length($out) > 0, 'channel generated output bytes for PING frame');

    $channel->check_keepalive();
    ok(1, 'check_keepalive executed successfully');
};



( run in 2.475 seconds using v1.01-cache-2.11-cpan-14f38c9f855 )