only check_timeout() when we did not receive anything

consider any received data a ping after we received the first
This commit is contained in:
Gunter Labes 2007-12-10 17:36:55 +00:00
parent 5e4c475b56
commit c399ece59e

View file

@ -151,7 +151,7 @@ static void check_timeout()
last_ping = 0;
return;
}
const time_t now = time(NULL);
const time_t& now = time(NULL);
DBG_NW << "Last ping: '" << last_ping << "' Current time: '" << now
<< "' Time since last ping: " << last_ping - now << "s\n";
// Reset last_ping if we didn't check for the last 10s.
@ -615,9 +615,6 @@ connection receive_data(config& cfg, connection connection_num, int timeout)
connection receive_data(config& cfg, connection connection_num)
{
if(last_ping != 0 && ping_timeout != 0 && !is_server() ) {
check_timeout();
}
if(!socket_set) {
return 0;
}
@ -671,6 +668,9 @@ connection receive_data(config& cfg, connection connection_num)
TCPsocket sock = connection_num == 0 ? 0 : get_socket(connection_num);
sock = network_worker_pool::get_received_data(sock,cfg);
if(sock == NULL) {
if(last_ping != 0 && ping_timeout != 0 && !is_server() ) {
check_timeout();
}
return 0;
}
@ -692,7 +692,9 @@ connection receive_data(config& cfg, connection connection_num)
if (ping != cfg.values.end()) {
LOG_NW << "Lag: " << (now - lexical_cast<time_t>(cfg["ping"])) << "\n";
last_ping = now;
}
} else if (last_ping != 0) {
last_ping = now;
}
}
return result;
}