I have a simple server socket
my $server = IO::Socket::INET->new(
LocalPort => $config{'local-port'},
Reuse => 1,
Listen => 10,
Timeout => 1,
Blocking => 1
) or croak "Couln't start server: $!\n";
I want to keep doing some routine while client is connected
while (1) {
my $client = $server->accept;
next unless $client;
say "new connection";
# this loop never ends
while ( $client->connected ) {
# do_work();
}
say "connection closed";
}
But $socket->connected always return true (or seemingly until tcp keepalive is not sent).
Is there a way to check if client is still connected (for example if it didn't send anything in 10 seconds it can be considered disconnected)?