AnyEvent-WebSocket-Client

 view release on metacpan or  search on metacpan

t/anyevent_websocket_connection__payload_size.t  view on Meta::CPAN

use lib 't/lib';
use Test2::Plugin::EV;
use Test2::Plugin::AnyEvent::Timeout;
use Test2::V0 -no_srand => 1;
use Test2::Tools::WebSocket::Connection qw( create_connection_and_handle );
use AnyEvent::WebSocket::Connection;
use AE;
use AnyEvent::WebSocket::Connection;
use Protocol::WebSocket::Frame;

my $connection;

{
  my @messages;
  my $message_cv = AE::cv;
  my $handle;

  ($connection, $handle) = create_connection_and_handle({ max_payload_size => 65538});
  note "connection.max_payload_size = @{[ $connection->max_payload_size ]}";

  my $frame = Protocol::WebSocket::Frame->new( max_payload_size => 0 );
  $handle->on_read(sub {
    #my($handle) = @_;
    $frame->append($handle->{rbuf});
    while(defined(my $body = $frame->next_bytes))
    {
      push @messages, AnyEvent::WebSocket::Message->new(
        body   => $body,
        opcode => $frame->opcode,
      );
      $message_cv->send;
    }
  });

  sub get_next_message
  {
    $message_cv->recv;
    $message_cv = AE::cv;
    shift @messages;
  }

  sub send_message
  {
    my($body,$cb) = @_;
    my $cv = AE::cv;
    if($cb)
    {
      $connection->on(next_message => sub {
        $cb->(@_);
        $cv->send;
      });
    }
    my $frame = Protocol::WebSocket::Frame->new(
      max_payload_size => 0,
      buffer => $body,
    );
    $handle->push_write($frame->to_bytes);
    $cv->recv if $cb;
  }

}

subtest 'send payload with size > 65536' => sub {

 view all matches for this distribution
 view release on metacpan -  search on metacpan

( run in 0.462 second using v1.00-cache-2.02-grep-82fe00e-cpan-2c419f77a38b )