comparison lib/Test/Nginx/HTTP2.pm @ 945:d73bef563aea

Tests: speed up HTTP/2 tests.
author Sergey Kandaurov <pluknet@nginx.com>
date Wed, 15 Jun 2016 13:27:56 +0300
parents 0d4536093b39
children 4dc302d8e04f
comparison
equal deleted inserted replaced
944:235f796c2861 945:d73bef563aea
58 my $len = defined $extra{len} ? $extra{len} : 8 + length($debug); 58 my $len = defined $extra{len} ? $extra{len} : 8 + length($debug);
59 my $buf = pack("x2C2xN3A*", $len, 0x7, $stream, $lstream, $err, $debug); 59 my $buf = pack("x2C2xN3A*", $len, 0x7, $stream, $lstream, $err, $debug);
60 60
61 my @bufs = map { 61 my @bufs = map {
62 raw_write($sess->{socket}, substr $buf, 0, $_, ""); 62 raw_write($sess->{socket}, substr $buf, 0, $_, "");
63 select undef, undef, undef, 0.4; 63 select undef, undef, undef, 0.2;
64 } @{$extra{split}}; 64 } @{$extra{split}};
65 65
66 raw_write($sess->{socket}, $buf); 66 raw_write($sess->{socket}, $buf);
67 } 67 }
68 68
263 sub h2_read { 263 sub h2_read {
264 my ($sess, %extra) = @_; 264 my ($sess, %extra) = @_;
265 my (@got); 265 my (@got);
266 my $s = $sess->{socket}; 266 my $s = $sess->{socket};
267 my $buf = ''; 267 my $buf = '';
268 my $wait = $extra{wait};
268 269
269 local $Data::Dumper::Terse = 1; 270 local $Data::Dumper::Terse = 1;
270 271
271 while (1) { 272 while (1) {
272 $buf = raw_read($s, $buf, 9); 273 $buf = raw_read($s, $buf, 9, \&log_in, $wait);
273 last if length $buf < 9; 274 last if length $buf < 9;
274 275
275 my $length = unpack_length($buf); 276 my $length = unpack_length($buf);
276 my $type = unpack('x3C', $buf); 277 my $type = unpack('x3C', $buf);
277 my $flags = unpack('x4C', $buf); 278 my $flags = unpack('x4C', $buf);
278 279
279 my $stream = unpack "x5 B32", $buf; 280 my $stream = unpack "x5 B32", $buf;
280 substr($stream, 0, 1) = 0; 281 substr($stream, 0, 1) = 0;
281 $stream = unpack("N", pack("B32", $stream)); 282 $stream = unpack("N", pack("B32", $stream));
282 283
283 $buf = raw_read($s, $buf, $length + 9); 284 $buf = raw_read($s, $buf, $length + 9, \&log_in, $wait);
284 last if length($buf) < $length + 9; 285 last if length($buf) < $length + 9;
285 286
286 $buf = substr($buf, 9); 287 $buf = substr($buf, 9);
287 288
288 my $frame = $cframe{$type}{value}($sess, $buf, $length, $flags, 289 my $frame = $cframe{$type}{value}($sess, $buf, $length, $flags,
408 sub unpack_length { 409 sub unpack_length {
409 unpack 'N', pack 'xc3', unpack 'c3', $_[0]; 410 unpack 'N', pack 'xc3', unpack 'c3', $_[0];
410 } 411 }
411 412
412 sub raw_read { 413 sub raw_read {
413 my ($s, $buf, $len, $log) = @_; 414 my ($s, $buf, $len, $log, $timo) = @_;
414 $log = \&log_in unless defined $log; 415 $log = \&log_in unless defined $log;
416 $timo = 3 unless $timo;
415 my $got = ''; 417 my $got = '';
416 418
417 while (length($buf) < $len && IO::Select->new($s)->can_read(1)) { 419 while (length($buf) < $len && IO::Select->new($s)->can_read($timo)) {
418 $s->sysread($got, 16384) or last; 420 $s->sysread($got, 16384) or last;
419 $log->($got); 421 $log->($got);
420 $buf .= $got; 422 $buf .= $got;
421 } 423 }
422 return $buf; 424 return $buf;