summaryrefslogtreecommitdiff
path: root/regress
diff options
context:
space:
mode:
Diffstat (limited to 'regress')
-rw-r--r--regress/usr.sbin/relayd/LICENSE2
-rw-r--r--regress/usr.sbin/relayd/args-http-filter-null-host.pl4
-rw-r--r--regress/usr.sbin/relayd/args-http-host3.pl2
-rw-r--r--regress/usr.sbin/relayd/args-http-slow-consumer.pl6
-rw-r--r--regress/usr.sbin/relayd/funcs.pl115
5 files changed, 74 insertions, 55 deletions
diff --git a/regress/usr.sbin/relayd/LICENSE b/regress/usr.sbin/relayd/LICENSE
index c8293e10125..150992ad397 100644
--- a/regress/usr.sbin/relayd/LICENSE
+++ b/regress/usr.sbin/relayd/LICENSE
@@ -1,4 +1,4 @@
-# Copyright (c) 2010-2015 Alexander Bluhm <bluhm@openbsd.org>
+# Copyright (c) 2010-2017 Alexander Bluhm <bluhm@openbsd.org>
# Copyright (c) 2014 Reyk Floeter <reyk@openbsd.org>
#
# Permission to use, copy, modify, and distribute this software for any
diff --git a/regress/usr.sbin/relayd/args-http-filter-null-host.pl b/regress/usr.sbin/relayd/args-http-filter-null-host.pl
index 2ce8f63a329..3ef85eb455d 100644
--- a/regress/usr.sbin/relayd/args-http-filter-null-host.pl
+++ b/regress/usr.sbin/relayd/args-http-filter-null-host.pl
@@ -10,8 +10,8 @@ my %header_client = (
our %args = (
client => {
- func => \&http_client,
- header => \%header_client,
+ func => \&http_client,
+ header => \%header_client,
httpnok => 1,
nocheck => 1,
},
diff --git a/regress/usr.sbin/relayd/args-http-host3.pl b/regress/usr.sbin/relayd/args-http-host3.pl
index 38bf6ca089f..ab2201396ea 100644
--- a/regress/usr.sbin/relayd/args-http-host3.pl
+++ b/regress/usr.sbin/relayd/args-http-host3.pl
@@ -29,7 +29,7 @@ EOF
},
server => {
func => \&http_server,
- nocheck => 1
+ nocheck => 1
},
);
diff --git a/regress/usr.sbin/relayd/args-http-slow-consumer.pl b/regress/usr.sbin/relayd/args-http-slow-consumer.pl
index bbdbfdabf3b..e8e6680b35c 100644
--- a/regress/usr.sbin/relayd/args-http-slow-consumer.pl
+++ b/regress/usr.sbin/relayd/args-http-slow-consumer.pl
@@ -19,8 +19,8 @@ our %args = (
http_request($self , $size, "1.0", "");
http_response($self , $size);
print STDERR "going to sleep\n";
- ${$self->{server}}->loggrep(qr/short write \($errors\)/, 8)
- or die "no short write in server.log";
+ ${$self->{server}}->loggrep(qr/blocked write/, 8)
+ or die "no blocked write in server.log";
read_char($self, $size);
return;
},
@@ -39,7 +39,7 @@ our %args = (
func => \&http_server,
sndbuf => 2**12,
sndtimeo => 2,
- loggrep => 'short write',
+ loggrep => qr/blocked write .*: $errors/,
},
lengths => [$size],
diff --git a/regress/usr.sbin/relayd/funcs.pl b/regress/usr.sbin/relayd/funcs.pl
index 06fffffe344..27f77a60a19 100644
--- a/regress/usr.sbin/relayd/funcs.pl
+++ b/regress/usr.sbin/relayd/funcs.pl
@@ -1,6 +1,6 @@
-# $OpenBSD: funcs.pl,v 1.22 2016/05/03 19:13:04 bluhm Exp $
+# $OpenBSD: funcs.pl,v 1.23 2017/07/14 14:41:03 bluhm Exp $
-# Copyright (c) 2010-2015 Alexander Bluhm <bluhm@openbsd.org>
+# Copyright (c) 2010-2017 Alexander Bluhm <bluhm@openbsd.org>
#
# Permission to use, copy, modify, and distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
@@ -51,25 +51,27 @@ sub find_ports {
sub write_syswrite {
my $self = shift;
my $buf = shift;
- my $len = 0;
- my $size = length($buf);
- my $r = 0;
+ IO::Handle::flush(\*STDOUT);
+ my $size = length($buf);
+ my $len = 0;
while ($len < $size) {
- while (($r = syswrite(STDOUT, $buf, $size, $len))) {
- $len += $r;
- if ($r != $size) {
- print STDERR "short write (only $r bytes)\n";
- }
+ my $n = syswrite(STDOUT, $buf, $size, $len);
+ if (!defined($n)) {
+ $!{EWOULDBLOCK}
+ or die ref($self), " syswrite failed: $!";
+ print STDERR "blocked write at $len of $size: $!\n";
+ next;
}
- if ($len != $size) {
- print STDERR "short write ($!)\n";
+ if ($len + $n != $size) {
+ print STDERR "short write $n at $len of $size\n";
}
+ $len += $n;
}
return $len;
}
-sub write_blocks {
+sub write_block {
my $self = shift;
my $len = shift;
@@ -79,22 +81,30 @@ sub write_blocks {
my $rest = $len % 1000;
for (my $i = 1; $i <= 100 ; $i++) {
- $data .= '012345678'."\n";
+ $data .= "012345678\n";
}
+ my $opct = 0;
for (my $i = 1; $i <= $blocks; $i++) {
- $outb += write_syswrite($self,$data);
- print STDERR ".";
+ $outb += write_syswrite($self, $data);
+ my $pct = ($outb / $len) * 100.0;
+ if ($pct >= $opct + 1) {
+ printf(STDERR "%.2f%% $outb/$len\n", $pct);
+ $opct = $pct;
+ }
}
if ($rest>0) {
for (my $i = 1; $i < $rest-1 ; $i++) {
- $outb += write_syswrite($self,'r');
- print STDERR ".";
+ $outb += write_syswrite($self, 'r');
+ my $pct = ($outb / $len) * 100.0;
+ if ($pct >= $opct + 1) {
+ printf(STDERR "%.2f%% $outb/$len\n", $pct);
+ $opct = $pct;
+ }
}
}
- print STDERR "\n";
- $outb += write_syswrite($self,"\n\n");
+ $outb += write_syswrite($self, "\n\n");
IO::Handle::flush(\*STDOUT);
print STDERR "LEN: ", $outb, "\n";
}
@@ -105,7 +115,7 @@ sub write_char {
my $sleep = $self->{sleep};
if ($self->{fast}) {
- write_blocks($self,$len);
+ write_block($self, $len);
return;
}
@@ -273,7 +283,8 @@ sub http_response {
if ($chunked) {
read_chunked($self);
} else {
- read_char($self, $vers eq "1.1" ? $len : undef)
+ undef $len unless defined($vers) && $vers eq "1.1";
+ read_char($self, $len)
if $method eq "GET";
}
}
@@ -327,25 +338,27 @@ sub errignore {
}
########################################################################
-# Server funcs
+# Common funcs
########################################################################
-sub read_char_fast {
+sub read_char {
my $self = shift;
my $max = shift // $self->{max};
+ if ($self->{fast}) {
+ read_block($self, $max);
+ return;
+ }
+
my $ctx = Digest::MD5->new();
my $len = 0;
if (defined($max) && $max == 0) {
print STDERR "Max\n";
} else {
- while ((my $r = sysread(STDIN, my $buf, POSIX::BUFSIZ))) {
- my $pct;
- $_ = $buf;
- $len += $r;
+ while (<STDIN>) {
+ $len += length($_);
$ctx->add($_);
- $pct = ($len / $max) * 100.0;
- printf(STDERR "%.2f%%\n", $pct);
+ print STDERR ".";
if (defined($max) && $len >= $max) {
print STDERR "\nMax";
last;
@@ -358,36 +371,42 @@ sub read_char_fast {
print STDERR "MD5: ", $ctx->hexdigest, "\n";
}
-sub read_char {
+sub read_block {
my $self = shift;
my $max = shift // $self->{max};
- if ($self->{fast}) {
- read_char_fast($self,$max);
- return;
- }
-
+ my $opct = 0;
my $ctx = Digest::MD5->new();
my $len = 0;
- if (defined($max) && $max == 0) {
- print STDERR "Max\n";
- } else {
- while (<STDIN>) {
- $len += length($_);
- $ctx->add($_);
- print STDERR ".";
- if (defined($max) && $len >= $max) {
- print STDERR "\nMax";
- last;
- }
+ for (;;) {
+ if (defined($max) && $len >= $max) {
+ print STDERR "Max\n";
+ last;
+ }
+ my $rlen = POSIX::BUFSIZ;
+ if (defined($max) && $rlen > $max - $len) {
+ $rlen = $max - $len;
+ }
+ defined(my $n = read(STDIN, my $buf, $rlen))
+ or die ref($self), " read failed: $!";
+ $n or last;
+ $len += $n;
+ $ctx->add($buf);
+ my $pct = ($len / $max) * 100.0;
+ if ($pct >= $opct + 1) {
+ printf(STDERR "%.2f%% $len/$max\n", $pct);
+ $opct = $pct;
}
- print STDERR "\n";
}
print STDERR "LEN: ", $len, "\n";
print STDERR "MD5: ", $ctx->hexdigest, "\n";
}
+########################################################################
+# Server funcs
+########################################################################
+
sub http_server {
my $self = shift;
my %header = %{$self->{header} || { Server => "Perl/".$^V }};