diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-03-09 13:19:48 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-03-09 13:20:02 +0000 |
commit | 58daab21cd043e1dc37024a7f99b396788372918 (patch) | |
tree | 96771e43bb69f7c1c2b0b4f7374cb74d7866d0cb /web/server/h2o/libh2o/misc/p5-Server-Starter/t/10-bindaddr.t | |
parent | Releasing debian version 1.43.2-1. (diff) | |
download | netdata-58daab21cd043e1dc37024a7f99b396788372918.tar.xz netdata-58daab21cd043e1dc37024a7f99b396788372918.zip |
Merging upstream version 1.44.3.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | web/server/h2o/libh2o/misc/p5-Server-Starter/t/10-bindaddr.t | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/web/server/h2o/libh2o/misc/p5-Server-Starter/t/10-bindaddr.t b/web/server/h2o/libh2o/misc/p5-Server-Starter/t/10-bindaddr.t new file mode 100644 index 000000000..16a76768c --- /dev/null +++ b/web/server/h2o/libh2o/misc/p5-Server-Starter/t/10-bindaddr.t @@ -0,0 +1,55 @@ +use strict; +use warnings; +use Test::More; +use Test::Requires qw(IO::Socket::IP); +use Net::EmptyPort qw(can_bind empty_port); +use Server::Starter qw(start_server); + +plan skip_all => 'IPv6 not available' + unless can_bind('::1'); + +my $port = empty_port; + +sub doit { + my ($bind_addr, $other_addr) = @_; + my $pid = fork; + die "fork failed:$!" + unless defined $pid; + if ($pid == 0) { + # server + start_server( + port => "[$bind_addr]:$port", + exec => [ + $^X, qw(t/10-bindaddr-server.pl), + ], + ); + exit 0; + } + # client + sleep 1; + my $sock = IO::Socket::IP->new( + PeerHost => $bind_addr, + PeerPort => $port, + Proto => 'tcp', + ); + ok($sock, "connected to bindaddr"); + $sock->sysread(my $buf, 1024); # wait for disconnect + undef $sock; + $sock = IO::Socket::IP->new( + PeerHost => $other_addr, + PeerPort => $port, + Proto => 'tcp', + ); + ok ! defined $sock, "cannot connect to other addr"; + kill 'TERM', $pid; + wait(); +} + +subtest "v4" => sub { + doit("127.0.0.1", "::1"); +}; +subtest "v6" => sub { + doit("::1", "127.0.0.1"); +}; + +done_testing; |