diff --git a/td/mtproto/SessionConnection.cpp b/td/mtproto/SessionConnection.cpp index dedd406fd..4a20035c1 100644 --- a/td/mtproto/SessionConnection.cpp +++ b/td/mtproto/SessionConnection.cpp @@ -979,16 +979,14 @@ Status SessionConnection::do_flush() { TRY_STATUS(raw_connection_->flush(auth_data_->get_auth_key(), *this)); - // check last pong - if (last_pong_at_ != 0 && last_pong_at_ + ping_disconnect_delay() < Time::now_cached()) { + if (last_pong_at_ + ping_disconnect_delay() < Time::now_cached()) { raw_connection_->stats_callback()->on_error(); - return Status::Error(PSLICE() << "No pong :( " << tag("rtt", rtt()) << tag("delay", ping_disconnect_delay())); + return Status::Error(PSLICE() << "Ping timeout of " << ping_disconnect_delay() << " seconds expired"); } - // check last pong - if (last_read_at_ != 0 && last_read_at_ + read_disconnect_delay() < Time::now_cached()) { + if (last_read_at_ + read_disconnect_delay() < Time::now_cached()) { raw_connection_->stats_callback()->on_error(); - return Status::Error("No read :("); + return Status::Error(PSLICE() << "Read timeout of " << read_disconnect_delay() << " seconds expired"); } return Status::OK(); diff --git a/td/mtproto/SessionConnection.h b/td/mtproto/SessionConnection.h index 777e0be49..4100427b9 100644 --- a/td/mtproto/SessionConnection.h +++ b/td/mtproto/SessionConnection.h @@ -130,7 +130,7 @@ class SessionConnection return max(2, static_cast(raw_connection_->rtt_ * 1.5 + 1)); } - int32 read_disconnect_delay() { + int32 read_disconnect_delay() const { return online_flag_ ? rtt() * 7 / 2 : 135; } @@ -149,8 +149,8 @@ class SessionConnection int http_max_wait() const { return 25 * 1000; // 25s. Longer could be closed by proxy } - static constexpr int HTTP_MAX_AFTER = 10; // 0.001s - static constexpr int HTTP_MAX_DELAY = 30; // 0.003s + static constexpr int HTTP_MAX_AFTER = 10; // 0.01s + static constexpr int HTTP_MAX_DELAY = 30; // 0.03s static constexpr int TEMP_KEY_TIMEOUT = 60 * 60 * 24; // one day vector to_send_;