You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm trying to use this library to connect to a server.
Everytime a connection is established a welcome message is sent from the server to the client. So I have the script with the following function:
sub create_sockets(Str $server,
Int $port,
Str $username,
Str $password,
Int $connections,
Bool $TLS,
Bool $insecure
--> List
){
my @socket_list;
my Lock $lock = Lock.new;
my @promises := do for 1..$connections -> $i {
start {
try {
my $conn;
if $TLS {
$conn = await IO::Socket::Async::SSL.connect($server, $port, :$insecure);
} else {
$conn = await IO::Socket::Async.connect($server, $port);
}
react whenever $conn.Supply -> $line {
print $line;
if $line ~~ /200/ {
await $conn.print("authenticate user $username\r\n");
} elsif $line ~~ /381/ {
await $conn.print("authenticate pass $password\r\n");
} elsif $line ~~ /281/ {
done;
} elsif $line ~~ /481/ {
$*ERR.print($line);
$conn.close;
exit(1);
}
}
$lock.protect: {
@socket_list.push($conn);
}
CATCH {
default {
$*ERR.say: "Got exception: { .Str.say; }\n{ .message }";
$*ERR.say: .backtrace.full;
.die;
}
}
}
}
}
my $all_done = Promise.allof(@promises);
await $all_done;
return @socket_list;
}
And sometimes it hangs.
Because i have a print $line in the react i can see that when it hangs, is because 1 socket that doesn't enter the react block. This never happens with "IO::Socket::Async" (The problem is also not on the server).
I'm not sure how can i debug this. This was the best i could come up with. Is there anything wrong with that function? How can i debug this?
Thanks in advance,
David Santiago
The text was updated successfully, but these errors were encountered:
I'm trying to use this library to connect to a server.
Everytime a connection is established a welcome message is sent from the server to the client. So I have the script with the following function:
And sometimes it hangs.
Because i have a
print $line
in the react i can see that when it hangs, is because 1 socket that doesn't enter the react block. This never happens with "IO::Socket::Async" (The problem is also not on the server).I'm not sure how can i debug this. This was the best i could come up with. Is there anything wrong with that function? How can i debug this?
Thanks in advance,
David Santiago
The text was updated successfully, but these errors were encountered: