Merge pull request #1434 from Barenboim/master

Enable setting 'watch timeout' for client tasks.
This commit is contained in:
xiehan
2023-11-28 16:46:15 +08:00
committed by GitHub
2 changed files with 10 additions and 1 deletions

View File

@@ -101,6 +101,7 @@ public:
void set_send_timeout(int timeout) { this->send_timeo = timeout; }
void set_receive_timeout(int timeout) { this->receive_timeo = timeout; }
void set_keep_alive(int timeout) { this->keep_alive_timeo = timeout; }
void set_watch_timeout(int timeout) { this->watch_timeo = timeout; }
...
}
~~~
@@ -110,7 +111,11 @@ set_receive_timeout()只对client任务有效指接收完整server回复的
set_keep_alive()接口设置连接保持超时。一般来讲,框架能很好的处理连接保持的问题,用户不需要调用。
如果是http协议client或server想要使用短连接可通过添加HTTP header来完成尽量不要用这个接口去修改。
如果一个redis client想要在请求之后关闭连接则需要用这个接口。显然在callback里set_keep_alive()是无效的(连接已经被复用)。
如果一个redis client想要在请求之后关闭连接则需要用这个接口。显然在callback里set_keep_alive()是无效的(连接已经被复用)。
set_watch_timeout()接口为client任务专有代表一个client任务的请求发出之后接收到第一个返回包的最大等待时间。
利用watch timeout可以避免一些需要等待数据推送的client任务受到response timeout和receive timeout的约束而超时。
设置了watch timeout之后从接收到第一个数据包再开始计算receive timeout。
### 任务的同步等待超时

View File

@@ -168,6 +168,7 @@ public:
void set_send_timeout(int timeout) { this->send_timeo = timeout; }
void set_receive_timeout(int timeout) { this->receive_timeo = timeout; }
void set_keep_alive(int timeout) { this->keep_alive_timeo = timeout; }
void set_watch_timeout(int timeout) { this->watch_timeo = timeout; }
public:
/* Do not reply this request. */
@@ -209,11 +210,13 @@ protected:
virtual int send_timeout() { return this->send_timeo; }
virtual int receive_timeout() { return this->receive_timeo; }
virtual int keep_alive_timeout() { return this->keep_alive_timeo; }
virtual int first_timeout() { return this->watch_timeo; }
protected:
int send_timeo;
int receive_timeo;
int keep_alive_timeo;
int watch_timeo;
REQ req;
RESP resp;
std::function<void (WFNetworkTask<REQ, RESP> *)> callback;
@@ -227,6 +230,7 @@ protected:
this->send_timeo = -1;
this->receive_timeo = -1;
this->keep_alive_timeo = 0;
this->watch_timeo = 0;
this->target = NULL;
this->timeout_reason = TOR_NOT_TIMEOUT;
this->user_data = NULL;