diff --git a/src/kernel/Communicator.cc b/src/kernel/Communicator.cc index 83412d2e..782d11ff 100644 --- a/src/kernel/Communicator.cc +++ b/src/kernel/Communicator.cc @@ -208,6 +208,13 @@ int CommMessageIn::feedback(const void *buf, size_t size) return ret; } +void CommMessageIn::renew() +{ + CommSession *session = this->entry->session; + session->timeout = -1; + session->begin_time.tv_nsec = -1; +} + int CommService::init(const struct sockaddr *bind_addr, socklen_t addrlen, int listen_timeout, int response_timeout) { diff --git a/src/kernel/Communicator.h b/src/kernel/Communicator.h index 08973710..92d4bb87 100644 --- a/src/kernel/Communicator.h +++ b/src/kernel/Communicator.h @@ -112,6 +112,9 @@ protected: /* Send small packet while receiving. Call only in append(). */ virtual int feedback(const void *buf, size_t size); + /* In append(), reset the begin time of receiving to current time. */ + virtual void renew(); + private: struct CommConnEntry *entry; @@ -158,6 +161,7 @@ private: public: CommSession() { this->passive = 0; } virtual ~CommSession(); + friend class CommMessageIn; friend class Communicator; }; diff --git a/src/protocol/PackageWrapper.cc b/src/protocol/PackageWrapper.cc index 4f4f1805..ed72431e 100644 --- a/src/protocol/PackageWrapper.cc +++ b/src/protocol/PackageWrapper.cc @@ -55,11 +55,17 @@ int PackageWrapper::append(const void *buf, size_t *size) { int ret = this->ProtocolWrapper::append(buf, size); - if (ret <= 0) - return ret; + if (ret > 0) + { + this->msg = this->next(this->msg); + if (this->msg) + { + this->renew(); + ret = 0; + } + } - this->msg = this->next(this->msg); - return !this->msg; + return ret; } } diff --git a/src/protocol/ProtocolMessage.h b/src/protocol/ProtocolMessage.h index c6393a7c..d466202b 100644 --- a/src/protocol/ProtocolMessage.h +++ b/src/protocol/ProtocolMessage.h @@ -81,6 +81,14 @@ protected: return this->CommMessageIn::feedback(buf, size); } + virtual void renew() + { + if (this->wrapper) + return this->wrapper->renew(); + else + return this->CommMessageIn::renew(); + } + protected: size_t size_limit;