Subject: | Net::GPSD3 hanging on polls |
Date: | Thu, 18 Aug 2016 16:22:47 +0200 |
To: | bug-Net-GPSD3 [...] rt.cpan.org |
From: | Stephan Riedel <raidlman [...] gmail.com> |
Hi,
recently I had a problem with hanging polls which ocured once in a while
and blocked my whole application. I use the module in a thread to poll
gpsd. Sig:SysAlarm's timeout_call and Time::Out's timeout weren't able to
terminate the hanging socket->readline (anyway, using signals in threads is
usually not a good idea...).
So I changed the constructor of the GPSD3 socket to use the
IO::Socket::Timeout module (
http://search.cpan.org/~dams/IO-Socket-Timeout-0.27/lib/IO/Socket/Timeout.pm).
This is now working really reliable and should be done like that by default
(imho).
I'm on Debian 8 and use the repository packages. The latest source looks a
little bit different but the same changes should work well.
Best regards,
Stephan
sub socket {
my $self = shift;
unless ( defined( $self->{'socket'} ) and defined(
$self->{'socket'}->connected ) ) {
$self->{"socket"} = IO::Socket::INET6->new(
PeerAddr => $self->host,
PeerPort => $self->port,
);
# enable and set timeouts for socket
IO::Socket::Timeout->enable_timeouts_on($self->{"socket"});
$self->{"socket"}->read_timeout(0.5);
$self->{"socket"}->write_timeout(0.5);
die(
sprintf(
"Error: Cannot connect to
gpsd://%s:%s/.\n",
$self->host, $self->port
)
) unless defined( $self->{"socket"} );
}
return $self->{'socket'};
}