Add CommMessageIn::renew() to reset begin time

This commit is contained in:
XieHan
2022-04-23 18:49:04 +08:00
parent dc6fd172a2
commit d2f6c484da
4 changed files with 29 additions and 4 deletions
+7
View File
@@ -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)
{
+4
View File
@@ -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;
};
+10 -4
View File
@@ -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;
}
}
+8
View File
@@ -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;