allow session level connect/response timeout

This commit is contained in:
XieHan
2021-07-27 19:33:30 +08:00
parent c8d1ec61cd
commit 01b3b47922
2 changed files with 12 additions and 3 deletions

View File

@@ -306,7 +306,7 @@ CommSession::~CommSession()
inline int Communicator::first_timeout(CommSession *session)
{
int timeout = session->target->response_timeout;
int timeout = session->response_timeout();
if (timeout < 0 || (unsigned int)session->timeout <= (unsigned int)timeout)
{
@@ -322,7 +322,7 @@ inline int Communicator::first_timeout(CommSession *session)
int Communicator::next_timeout(CommSession *session)
{
int timeout = session->target->response_timeout;
int timeout = session->response_timeout();
struct timespec cur_time;
int time_used, time_left;
@@ -1496,6 +1496,7 @@ int Communicator::request(CommSession *session, CommTarget *target)
struct CommConnEntry *entry;
struct poller_data data;
int errno_bak;
int timeout;
int ret;
if (session->passive)
@@ -1520,7 +1521,8 @@ int Communicator::request(CommSession *session, CommTarget *target)
data.fd = entry->sockfd;
data.ssl = NULL;
data.context = entry;
if (mpoller_add(&data, target->connect_timeout, this->mpoller) >= 0)
timeout = session->connect_timeout();
if (mpoller_add(&data, timeout, this->mpoller) >= 0)
break;
this->release_conn(entry);

View File

@@ -50,6 +50,9 @@ public:
*addrlen = this->addrlen;
}
int get_connect_timeout() const { return this->connect_timeout; }
int get_response_timeout() const { return this->response_timeout; }
protected:
void set_ssl(SSL_CTX *ssl_ctx, int ssl_connect_timeout)
{
@@ -136,6 +139,10 @@ private:
virtual int first_timeout() { return 0; } /* for client session only. */
virtual void handle(int state, int error) = 0;
private:
virtual int connect_timeout() { return this->target->connect_timeout; }
virtual int response_timeout() { return this->target->response_timeout; }
protected:
CommTarget *get_target() const { return this->target; }
CommConnection *get_connection() const { return this->conn; }