AnyEvent-GPSD
view release on metacpan or search on metacpan
162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
&$event
;
}
}
sub
retry {
my
(
$self
) =
@_
;
delete
$self
->{fh};
delete
$self
->{command};
Scalar::Util::weaken
$self
;
$self
->{retry_w} = AnyEvent->timer (
after
=> 1,
cb
=>
sub
{
delete
$self
->{retry_w};
$self
->
connect
;
});
}
# make sure we send "no fix" updates when we lose connectivity
sub
interval_timer {
my
(
$self
) =
@_
;
$self
->{interval_w} = AnyEvent->timer (
after
=>
$self
->{interval},
cb
=>
sub
{
if
(AnyEvent->now -
$self
->{fix}{
time
} >
$self
->{interval} * 1.9) {
$self
->{fix}{mode} = 1;
$self
->event (
fix
=>
$self
->{fix});
}
$self
->interval_timer;
});
Scalar::Util::weaken
$self
;
}
sub
connect
{
my
(
$self
) =
@_
;
return
if
$self
->{fh};
AnyEvent::Socket::tcp_connect
$self
->{host} ||
"localhost"
,
$self
->{port} || 2947,
sub
{
my
(
$fh
) =
@_
;
238239240241242243244245246247248249250251252253254255256257258
$self
->
send
(
"y"
);
$self
->
send
(
"c"
);
$self
->event (
"connect"
);
$self
->
log
(
"connect"
);
}
else
{
$self
->event (
"error"
);
}
};
Scalar::Util::weaken
$self
;
}
sub
drain_wbuf {
my
(
$self
) =
@_
;
$self
->{fh}->push_write (
join
""
, @{
$self
->{command}[0] });
}
sub
send
{
my
(
$self
,
$command
,
$args
) =
@_
;
469470471472473474475476477478479480481482483484485486487488489require
JSON;
open
my
$fh
,
"<:perlio"
,
$path
or Carp::croak
"$path: $!"
;
$self
->{stretch} =
$option
{stretch} || 1;
$self
->{compress} =
$option
{compress};
$self
->{imterval} /=
$self
->{stretch};
Scalar::Util::weaken
$self
;
$self
->{replay_cb} =
sub
{
my
$line
= <
$fh
>;
if
(2 >
length
$line
) {
$self
->replay_log;
}
else
{
my
(
$time
,
$type
,
@data
) = @{ JSON::decode_json (
$line
) };
$time
*=
$self
->{stretch};
( run in 0.317 second using v1.01-cache-2.11-cpan-a9ef4e587e4 )