diff --git a/S32-io/IO-Socket-Async-UDP.t b/S32-io/IO-Socket-Async-UDP.t index 4bce5873c7..639c6d63f6 100644 --- a/S32-io/IO-Socket-Async-UDP.t +++ b/S32-io/IO-Socket-Async-UDP.t @@ -1,45 +1,51 @@ use v6; use Test; -plan 3; +plan 5; my $hostname = 'localhost'; my $port = 5001; { - my $sock = IO::Socket::Async.bind-udp($hostname, $port); + my $s = IO::Socket::Async.bind-udp($hostname, $port); dies-ok { IO::Socket::Async.bind-udp($hostname, $port) }, 'Error on trying to re-use port with UDP bind'; - $sock.close; + $s.close; } # Promise used to check listener received the correct data. -my $rec-prom; - -# Listener -{ - my $sock = IO::Socket::Async.bind-udp($hostname, $port); - my $tap = $sock.Supply.tap: -> $chars { - if $chars.chars > 0 { - $rec-prom.keep($chars); - } +my Promise $rec-prom; +my $s = IO::Socket::Async.bind-udp($hostname, $port); +my $tap = $s.Supply.tap: -> $chars { + if $chars.chars > 0 { + $rec-prom.keep($chars); } } # Client print-to { - $rec-prom = Promise.new; - my $sock = IO::Socket::Async.udp(); - $sock.print-to($hostname, $port, "Unusually Dubious Protocol"); + $rec-prom .= new; + my $c = IO::Socket::Async.udp(); + $c.print-to($hostname, $port, "Unusually Dubious Protocol"); is $rec-prom.result, "Unusually Dubious Protocol", "Sent/received data with UDP (print)"; - $sock.close; + $c.close; } # Client write-to { - $rec-prom = Promise.new; - my $sock = IO::Socket::Async.udp(); - $sock.write-to($hostname, $port, "Unhelpful Dataloss Protocol".encode('ascii')); + $rec-prom .= new; + my $c = IO::Socket::Async.udp(); + $c.write-to($hostname, $port, "Unhelpful Dataloss Protocol".encode('ascii')); is $rec-prom.result, "Unhelpful Dataloss Protocol", "Sent/received data with UDP (write)"; - $sock.close; + $c.close; +} + +#?rakudo.jvm skip 'nqp::filenofh not yet implemented on the JVM' +{ + my $c = IO::Socket::Async.udp(); + cmp-ok $s.native-descriptor, '>', -1, 'server file descriptor makes sense'; + cmp-ok $c.native-descriptor, '>', -1, 'client file descriptor makes sense'; + $c.close; } + +$s.close; diff --git a/S32-io/IO-Socket-Async.t b/S32-io/IO-Socket-Async.t index dfcc13a6bc..359e50e2db 100644 --- a/S32-io/IO-Socket-Async.t +++ b/S32-io/IO-Socket-Async.t @@ -1,7 +1,7 @@ use v6; use Test; -plan 38; +plan 41; my $hostname = 'localhost'; my $port = 5000; @@ -292,3 +292,22 @@ for '127.0.0.1', '::1' -> $host { is @first-got.join(""), "hello first", "first server socket got the right message"; is @second-got.join(""), "hello second", "second server socket got the right message"; } + +#?rakudo.jvm skip 'nqp::filenofh not yet implemented on the JVM' +{ + my Promise $p .= new; + my $v = $p.vow; + + my $s = IO::Socket::Async.listen('localhost', 0).tap(-> $c { + cmp-ok $c.native-descriptor, '>', -1, 'server peer file descriptor makes sense'; + $v.keep: 1; + }); + cmp-ok $s.native-descriptor, '>', -1, 'server file descriptor makes sense'; + + my $c = await IO::Socket::Async.connect: 'localhost', await $s.socket-port; + cmp-ok $c.native-descriptor, '>', -1, 'client file descriptor makes sense'; + + await $p; + $s.close; + $c.close; +}