From 16707b0602d854d669770ac155e085c9de339537 Mon Sep 17 00:00:00 2001 From: levlam Date: Tue, 20 Nov 2018 20:52:42 +0300 Subject: [PATCH] Minor improvements. GitOrigin-RevId: 25ac84d8020557804fc89845e9764c3d50b098d3 --- td/mtproto/SessionConnection.cpp | 10 ++++------ td/mtproto/SessionConnection.h | 6 +++--- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/td/mtproto/SessionConnection.cpp b/td/mtproto/SessionConnection.cpp index dedd406f..4a20035c 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 777e0be4..4100427b 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_;