Skip to content

Commit

Permalink
Fix TCP session issue.
Browse files Browse the repository at this point in the history
  • Loading branch information
mobizt committed Apr 7, 2024
1 parent 91e4003 commit c79f37f
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 15 deletions.
2 changes: 1 addition & 1 deletion library.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "FirebaseClient",
"version": "1.0.11",
"version": "1.0.12",
"keywords": "communication, REST, esp32, esp8266, arduino",
"description": "Async Firebase Client library for Arduino.",
"repository": {
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name=FirebaseClient

version=1.0.11
version=1.0.12

author=Mobizt

Expand Down
2 changes: 1 addition & 1 deletion src/FirebaseClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
#undef FIREBASE_CLIENT_VERSION
#endif

#define FIREBASE_CLIENT_VERSION "1.0.11"
#define FIREBASE_CLIENT_VERSION "1.0.12"

#include <Arduino.h>
#include "./core/FirebaseApp.h"
Expand Down
28 changes: 16 additions & 12 deletions src/core/AsyncClient/AsyncClient.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Created April 6, 2024
* Created April 7, 2024
*
* For MCU build target (CORE_ARDUINO_XXXX), see Options.h.
*
Expand Down Expand Up @@ -47,15 +47,6 @@

using namespace firebase;

__attribute__((unused)) static void meminfo(int pos)
{
#if defined(ESP8266)
Serial.printf("Pos: %d, Heap: %d, Stack: %d\n", pos, ESP.getFreeHeap(), ESP.getFreeContStack());
#elif defined(ESP32)
Serial.printf("Pos: %d, Heap: %d\n", pos, ESP.getFreeHeap());
#endif
}

enum async_state
{
async_state_undefined,
Expand Down Expand Up @@ -197,6 +188,8 @@ class AsyncClientClass
#endif
async_request_handler_t::tcp_client_type client_type = async_request_handler_t::tcp_client_type_sync;
bool sse = false;
String host;
uint16_t port;
std::vector<uint32_t> sVec;
Memory mem;
Base64Util but;
Expand Down Expand Up @@ -232,6 +225,13 @@ class AsyncClientClass
return true;
}

void newCon(async_data_item_t *sData, const char *host, uint16_t port)
{
if ((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);
}

function_return_type sendHeader(async_data_item_t *sData, const char *data)
{
return send(sData, (uint8_t *)data, data ? strlen(data) : 0, data ? strlen(data) : 0, async_state_send_header);
Expand Down Expand Up @@ -504,8 +504,7 @@ class AsyncClientClass

if (sData->state == async_state_undefined || sData->state == async_state_send_header)
{
if ((sse && !sData->sse) || (!sse && sData->sse) || (sData->auth_used && sData->state == async_state_undefined))
stop(sData);
newCon(sData, getHost(sData, true).c_str(), sData->request.port);

if ((client_type == async_request_handler_t::tcp_client_type_sync && !client->connected()) || client_type == async_request_handler_t::tcp_client_type_async)
{
Expand Down Expand Up @@ -1314,6 +1313,8 @@ class AsyncClientClass
#endif
}

this->host = host;
this->port = port;
return sData->return_type;
}

Expand Down Expand Up @@ -1870,6 +1871,9 @@ class AsyncClientClass
async_tcp_config->tcpStop();
#endif
}

clear(host);
port = 0;
}

FirebaseError lastError() const { return lastErr; }
Expand Down

0 comments on commit c79f37f

Please sign in to comment.