[Slim-Checkins] r8810 - /trunk/server/Slim/Networking/Slimproto.pm
andy at svn.slimdevices.com
andy at svn.slimdevices.com
Sat Aug 5 06:00:09 PDT 2006
Author: andy
Date: Sat Aug 5 06:00:08 2006
New Revision: 8810
URL: http://svn.slimdevices.com?rev=8810&view=rev
Log:
Use a variable for check_all_clients timer
Modified:
trunk/server/Slim/Networking/Slimproto.pm
Modified: trunk/server/Slim/Networking/Slimproto.pm
URL: http://svn.slimdevices.com/trunk/server/Slim/Networking/Slimproto.pm?rev=8810&r1=8809&r2=8810&view=diff
==============================================================================
--- trunk/server/Slim/Networking/Slimproto.pm (original)
+++ trunk/server/Slim/Networking/Slimproto.pm Sat Aug 5 06:00:08 2006
@@ -34,9 +34,10 @@
my $forget_disconnected_time = 300; # disconnected clients will be forgotten unless they reconnect before this
+my $check_all_clients_time = 5; # how often to look for disconnected clients
+my $last_check; # last time check_all_clients ran
+
my $slimproto_socket;
-
-my $last_check = 0; # last time check_all_clients ran
our %ipport; # ascii IP:PORT
our %inputbuffer; # inefficiently append data here until we have a full slimproto frame
@@ -115,7 +116,8 @@
Slim::Networking::Select::addRead($slimproto_socket, \&slimproto_accept);
# Bug 2707, This timer checks for players that have gone away due to a power loss and disconnects them
- Slim::Utils::Timers::setTimer( undef, Time::HiRes::time() + 5, \&check_all_clients );
+ $last_check = time();
+ Slim::Utils::Timers::setTimer( undef, Time::HiRes::time() + $check_all_clients_time, \&check_all_clients );
$::d_slimproto && msg "Squeezebox protocol listening on port $listenerport\n";
}
@@ -176,27 +178,42 @@
for my $client ( values %sock2client ) {
+ # SoftSqueeze does not report status
+ next if $client->isa('Slim::Player::SoftSqueeze');
+
+ # skip if we haven't yet heard anything
+ if ( !defined $heartbeat{$client} ) {
+ $client->requestStatus();
+ next;
+ }
+
+ # adjust in case the server is running slow
+ if ( $now - $last_check > $check_all_clients_time ) {
+ $now = $last_check + $check_all_clients_time;
+ }
+
# check when we last heard a stat response from the player
-
- my $last_heard = $now - ($heartbeat{ $client->id } || $now);
-
- if ( $last_heard > 2 ) {
- $client->requestStatus();
- }
-
- if ( $last_heard > 15 && ($now - $last_check) < 10 ) {
+ my $last_heard = $now - $heartbeat{$client};
+
+ if ( $last_heard >= $check_all_clients_time * 2 ) {
$::d_slimproto && msgf("Haven't heard from %s in %d seconds, closing connection\n",
$client->id,
$last_heard,
);
slimproto_close( $client->tcpsock );
+ next;
+ }
+
+ # force a status request if we haven't heard from the player in a short while
+ if ( $last_heard >= $check_all_clients_time / 2 ) {
+ $client->requestStatus();
}
}
$last_check = $now;
- Slim::Utils::Timers::setTimer( undef, $now + 5, \&check_all_clients );
-}
+ Slim::Utils::Timers::setTimer( undef, $now + $check_all_clients_time, \&check_all_clients );
+}
sub slimproto_close {
my $clientsock = shift;
@@ -214,7 +231,7 @@
if ( my $client = $sock2client{$clientsock} ) {
- delete $heartbeat{ $client->id };
+ delete $heartbeat{$client};
# check client not already forgotten
if ( Slim::Player::Client::getClient( $client->id ) ) {
@@ -513,7 +530,7 @@
my $data_ref = shift;
# update the heartbeat value for this player
- $heartbeat{ $client->id } = time;
+ $heartbeat{$client} = time();
#struct status_struct {
# u32_t event;
More information about the checkins
mailing list