From ef1a526ccdc7fcb75dcab09fa9ae9037373d5105 Mon Sep 17 00:00:00 2001 From: xiehan <52160700+Barenboim@users.noreply.github.com> Date: Fri, 9 Aug 2024 22:55:52 +0800 Subject: [PATCH] Use CommSession::first_timeout() when message was renewed in append(). (#1603) --- src/kernel/Communicator.cc | 25 +++++++++++++++++++------ src/kernel/Communicator.h | 2 +- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/src/kernel/Communicator.cc b/src/kernel/Communicator.cc index 91e97c4c..5d13caed 100644 --- a/src/kernel/Communicator.cc +++ b/src/kernel/Communicator.cc @@ -205,6 +205,7 @@ void CommMessageIn::renew() { CommSession *session = this->entry->session; session->timeout = -1; + session->begin_time.tv_sec = -1; session->begin_time.tv_nsec = -1; } @@ -372,7 +373,6 @@ inline int Communicator::first_timeout(CommSession *session) { timeout = session->timeout; session->timeout = 0; - session->begin_time.tv_nsec = 0; } else clock_gettime(CLOCK_MONOTONIC, &session->begin_time); @@ -508,7 +508,8 @@ int Communicator::send_message_sync(struct iovec vectors[], int cnt, else { session->timeout = -1; - session->begin_time.tv_nsec = -1; + session->begin_time.tv_sec = -1; + session->begin_time.tv_nsec = 0; } mpoller_set_timeout(entry->sockfd, timeout, this->mpoller); @@ -850,7 +851,8 @@ void Communicator::handle_request_result(struct poller_result *res) else { session->timeout = -1; - session->begin_time.tv_nsec = -1; + session->begin_time.tv_sec = -1; + session->begin_time.tv_nsec = 0; } if (mpoller_add(&res->data, timeout, this->mpoller) >= 0) @@ -964,7 +966,8 @@ void Communicator::handle_connect_result(struct poller_result *res) else { session->timeout = -1; - session->begin_time.tv_nsec = -1; + session->begin_time.tv_sec = -1; + session->begin_time.tv_nsec = 0; } } else if (ret > 0) @@ -1286,8 +1289,18 @@ int Communicator::append_message(const void *buf, size_t *size, } else if (ret == 0 && session->timeout != 0) { - if (session->begin_time.tv_nsec == -1) - timeout = Communicator::first_timeout_recv(session); + if (session->begin_time.tv_sec < 0) + { + if (session->begin_time.tv_nsec < 0) + timeout = session->first_timeout(); + else + timeout = 0; + + if (timeout == 0) + timeout = Communicator::first_timeout_recv(session); + else + session->begin_time.tv_nsec = 0; + } else timeout = Communicator::next_timeout(session); } diff --git a/src/kernel/Communicator.h b/src/kernel/Communicator.h index 3658bf68..2c5f7e08 100644 --- a/src/kernel/Communicator.h +++ b/src/kernel/Communicator.h @@ -140,7 +140,7 @@ private: virtual int send_timeout() { return -1; } virtual int receive_timeout() { return -1; } virtual int keep_alive_timeout() { return 0; } - virtual int first_timeout() { return 0; } /* for client session only. */ + virtual int first_timeout() { return 0; } virtual void handle(int state, int error) = 0; protected: