Skip to content

Commit

Permalink
Add read and send timeout for sync task.
Browse files Browse the repository at this point in the history
  • Loading branch information
mobizt committed Apr 5, 2024
1 parent f3bc54b commit 3d9f580
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 33 deletions.
48 changes: 25 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ This library is [Firebase-ESP-Client](https://github.com/mobizt/Firebase-ESP-Cli

- [Async Client](#async-client)

- [Send and Read timeouts for Sync and Async Tasks](#send-and-read-timeouts-for-sync-and-async-tasks)

- [The Static Async Result Instances Required for Async Operation](#the-static-async-result-instances-required-for-async-operation)

- [Dangling Pointers Prevention](#dangling-pointers-prevention)
Expand Down Expand Up @@ -76,8 +78,6 @@ This library is [Firebase-ESP-Client](https://github.com/mobizt/Firebase-ESP-Cli

- [Basic Example](#basic-example)

- [Firebase and Google Services Classes](#firebase-and-google-services)

- [Realtime Database Usage](#realtime-database-usage)

- [Google Cloud Firestore Database Usage](#google-cloud-firestore-database-usage)
Expand Down Expand Up @@ -313,6 +313,23 @@ Non-authentication (for testing only) and user management classes and functions

The Firebase and Google services Classes that are available are Realtime database, Cloud Firestore database, Cloud Messaging, Firebase Storage, Cloud Functions and Google Cloud Storage classes.

- [RealtimeDatabase](examples/RealtimeDatabase/) is for Realtime database operation.

- [Firestore::Databases](examples/FirestoreDatabase/Databases/) is for Cloud Firestore databases operation.

- [Firestore::Documents](examples/FirestoreDatabase/Documents/) is for Cloud Firestore documents operation.

- [Firestore::CollectionGroups::Indexes](examples/FirestoreDatabase/CollectionGroups/Indexes/) is for Cloud Firestore CollectionGroups's Indexes operation.

- [Messaging](examples/Messaging/) is for Cloud Messaging operation.

- [Storage](examples/Storage/) is for Firebase Storage operation.

- [CloudStorage](examples/CloudStorage/) is for Google Cloud Storage operation.

- [CloudFunctions](examples/CloudFunctions/) is for Google Cloud Functions operation.


This library used internal millis timer to handle the token time to live. Then device time setting is not requierd in most authentication types.

In access and custom token authentications using service accout file (sa and custom auths), it related to JWT token creation and the token signing using RSA private key. This process require the valid timestamp, then the time status setting callback will be required in the sa and custom auth class constructor.
Expand Down Expand Up @@ -363,6 +380,12 @@ The SSL Client is a kind of sync or blocking Client that takes time during estab

The async SSL client can be assigned to the async client class constructor but currently experimental.

### Send and Read timeouts for Sync and Async Tasks

The default send and read timeouts for async task are 30 seconds and cannot be changed.

For sync task, the timeout in seconds can be set via the `AsyncClientClass` member functions, `setSyncSendTimeout` and `setSyncReadTimeout`.


### The Static Async Result Instances Required for Async Operation

Expand Down Expand Up @@ -1129,27 +1152,6 @@ If the size of payload string in async reseut is large, to copy the char array b
There is no JSON serialization/deserialization utilized or provided in this library.
### Firebase and Google Services Classes
- [RealtimeDatabase](examples/RealtimeDatabase/) is for Realtime database operation.
- [Firestore::Databases](examples/FirestoreDatabase/Databases/) is for Cloud Firestore databases operation.
- [Firestore::Documents](examples/FirestoreDatabase/Documents/) is for Cloud Firestore documents operation.
- [Firestore::CollectionGroups::Indexes](examples/FirestoreDatabase/CollectionGroups/Indexes/) is for Cloud Firestore CollectionGroups's Indexes operation.
- [Messaging](examples/Messaging/) is for Cloud Messaging operation.
- [Storage](examples/Storage/) is for Firebase Storage operation.
- [CloudStorage](examples/CloudStorage/) is for Google Cloud Storage operation.
- [CloudFunctions](examples/CloudFunctions/) is for Google Cloud Functions operation.
## Realtime Database Usage
- [Examples](/examples/RealtimeDatabase).
Expand Down
2 changes: 2 additions & 0 deletions keywords.txt
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,8 @@ setDebugLevel KEYWORD2
setClient KEYWORD2
setBufferSizes KEYWORD2
setInsecure KEYWORD2
setSyncSendTimeout KEYWORD2
setSyncReadTimeout KEYWORD2

###################
# Struct (KEYWORD3)
Expand Down
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.6",
"version": "1.0.7",
"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.6
version=1.0.7

author=Mobizt

Expand Down
2 changes: 1 addition & 1 deletion src/FirebaseClient.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Created March 31, 2024
* Created April 6, 2024
*
* The MIT License (MIT)
* Copyright (c) 2024 K. Suwatchai (Mobizt)
Expand Down
15 changes: 10 additions & 5 deletions src/core/AsyncClient/AsyncClient.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Created March 31, 2024
* Created April 6, 2024
*
* For MCU build target (CORE_ARDUINO_XXXX), see Options.h.
*
Expand Down Expand Up @@ -188,6 +188,7 @@ class AsyncClientClass
int netErrState = 0;
uint32_t auth_ts = 0;
uint32_t cvec_addr = 0;
uint32_t sync_send_timeout_sec = 0, sync_read_timeout_sec = 0;
Client *client = nullptr;
#if defined(ENABLE_ASYNC_TCP_CLIENT)
AsyncTCPConfig *async_tcp_config = nullptr;
Expand Down Expand Up @@ -1015,7 +1016,7 @@ class AsyncClientClass

if (sData->response.flags.payload_remaining)
{
sData->response.feedTimer();
sData->response.feedTimer(!sData->async && sync_read_timeout_sec > 0 ? sync_read_timeout_sec : -1);

// the next chunk data is the payload
if (sData->response.httpCode != FIREBASE_ERROR_HTTP_CODE_NO_CONTENT)
Expand Down Expand Up @@ -1873,6 +1874,10 @@ class AsyncClientClass

void setETag(const String &etag) { reqEtag = etag; }

void setSyncSendTimeout(uint32_t timeoutSec) { sync_send_timeout_sec = timeoutSec; }

void setSyncReadTimeout(uint32_t timeoutSec) { sync_read_timeout_sec = timeoutSec; }

async_data_item_t *createSlot(slot_options_t &options)
{
int slot_index = sMan(options);
Expand Down Expand Up @@ -2013,14 +2018,14 @@ class AsyncClientClass
if (sData->state == async_state_undefined || sData->state == async_state_send_header || sData->state == async_state_send_payload)
{
sData->response.clear();
sData->request.feedTimer();
sData->request.feedTimer(!sData->async && sync_send_timeout_sec > 0 ? sync_send_timeout_sec : -1);
sending = true;
sData->return_type = send(sData);

while (sData->state == async_state_send_header || sData->state == async_state_send_payload)
{
sData->return_type = send(sData);
sData->response.feedTimer();
sData->response.feedTimer(!sData->async && sync_read_timeout_sec > 0 ? sync_read_timeout_sec : -1);
handleSendTimeout(sData);
if (sData->async || sData->return_type == function_return_type_failure)
break;
Expand Down Expand Up @@ -2074,7 +2079,7 @@ class AsyncClientClass
sData->error.code = 0;
while (sData->return_type == function_return_type_continue && (sData->response.httpCode == 0 || sData->response.flags.header_remaining || sData->response.flags.payload_remaining))
{
sData->response.feedTimer();
sData->response.feedTimer(!sData->async && sync_read_timeout_sec > 0 ? sync_read_timeout_sec : -1);
sData->return_type = receive(sData);

handleReadTimeout(sData);
Expand Down
2 changes: 1 addition & 1 deletion src/core/AsyncClient/RequestHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
#include "./core/AsyncTCPConfig.h"
#endif

#define FIREBASE_TCP_WRITE_TIMEOUT_SEC 30
#define FIREBASE_TCP_WRITE_TIMEOUT_SEC 30 // Do not change

#define FIREBASE_AUTH_PLACEHOLDER (const char *)FPSTR("<auth_token>")

Expand Down
2 changes: 1 addition & 1 deletion src/core/AsyncClient/ResponseHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
#include <Client.h>
#include "RequestHandler.h"

#define FIREBASE_TCP_READ_TIMEOUT_SEC 30
#define FIREBASE_TCP_READ_TIMEOUT_SEC 30 // Do not change

namespace res_hndlr_ns
{
Expand Down

0 comments on commit 3d9f580

Please sign in to comment.