Skip to content

Commit

Permalink
Add support TCP session timeout for session reusage
Browse files Browse the repository at this point in the history
  • Loading branch information
mobizt committed Jun 25, 2024
1 parent 46b811c commit 0abec1c
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions src/core/AsyncClient/AsyncClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -183,10 +183,11 @@ class AsyncClientClass : public ResultBase, RTDBResultBase
AsyncResult *refResult = nullptr;
AsyncResult aResult;
int netErrState = 0;
uint32_t auth_ts = 0, conn_ts = 0;
uint32_t auth_ts = 0;
uint32_t cvec_addr = 0;
uint32_t result_addr = 0;
uint32_t sync_send_timeout_sec = 0, sync_read_timeout_sec = 0;
Timer session_timer;
Client *client = nullptr;
#if defined(ENABLE_ASYNC_TCP_CLIENT)
AsyncTCPConfig *async_tcp_config = nullptr;
Expand Down Expand Up @@ -234,13 +235,8 @@ class AsyncClientClass : public ResultBase, RTDBResultBase

void newCon(async_data_item_t *sData, const char *host, uint16_t port)
{
#if defined(FIREBASE_SESSION_TIMEOUT)
int session_timeout_msec = FIREBASE_SESSION_TIMEOUT * 60 * 1000;
#else
int session_timeout_msec = 3 * 60 * 1000;
#endif

if ((!sData->sse && conn_ts > 0 && millis() - conn_ts > session_timeout_msec) || (sse && !sData->sse) || (!sse && sData->sse) || (sData->auth_used && sData->state == async_state_undefined) ||
if ((!sData->sse && session_timer.remaining() == 0) || (sse && !sData->sse) || (!sse && sData->sse) || (sData->auth_used && sData->state == async_state_undefined) ||
strcmp(this->host.c_str(), host) != 0 || this->port != port)
{
stop(sData);
Expand Down Expand Up @@ -1432,8 +1428,14 @@ class AsyncClientClass : public ResultBase, RTDBResultBase
this->host = host;
this->port = port;

if (client && !client->connected())
conn_ts = millis();
if (client && client->connected())
{
#if defined(FIREBASE_SESSION_TIMEOUT)
session_timer.feed(FIREBASE_SESSION_TIMEOUT);
#else
session_timer.feed(3 * 60);
#endif
}

return sData->return_type;
}
Expand Down Expand Up @@ -2011,7 +2013,6 @@ class AsyncClientClass : public ResultBase, RTDBResultBase

clear(host);
port = 0;
conn_ts = 0;
}

async_data_item_t *createSlot(slot_options_t &options)
Expand Down

0 comments on commit 0abec1c

Please sign in to comment.