Skip to content

Commit

Permalink
Disconnect if no data received in more than 10 minutes
Browse files Browse the repository at this point in the history
  • Loading branch information
eandersson committed Feb 4, 2025
1 parent 548f914 commit 406dc5c
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions main/tasks/stratum_task.c
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,9 @@ void stratum_task(void * pvParameters)
int ip_protocol = IPPROTO_IP;
int retry_attempts = 0;
int retry_critical_attempts = 0;

struct timeval timeout = {};
timeout.tv_sec = 5;
timeout.tv_sec = 600;
timeout.tv_usec = 0;

xTaskCreate(stratum_primary_heartbeat, "stratum primary heartbeat", 4096, pvParameters, 1, NULL);
Expand Down Expand Up @@ -226,12 +227,15 @@ void stratum_task(void * pvParameters)
vTaskDelay(5000 / portTICK_PERIOD_MS);
continue;
}
retry_attempts = 0;

if (setsockopt(GLOBAL_STATE->sock, SOL_SOCKET, SO_SNDTIMEO, &timeout, sizeof(timeout)) != 0) {
ESP_LOGE(TAG, "Fail to setsockopt SO_SNDTIMEO");
}

if (setsockopt(GLOBAL_STATE->sock, SOL_SOCKET, SO_RCVTIMEO , &timeout, sizeof(timeout)) != 0) {
ESP_LOGE(TAG, "Fail to setsockopt SO_RCVTIMEO ");
}

STRATUM_V1_reset_uid();
cleanQueue(GLOBAL_STATE);

Expand All @@ -258,9 +262,12 @@ void stratum_task(void * pvParameters)
char * line = STRATUM_V1_receive_jsonrpc_line(GLOBAL_STATE->sock);
if (!line) {
ESP_LOGE(TAG, "Failed to receive JSON-RPC line, reconnecting...");
retry_attempts++;
stratum_close_connection(GLOBAL_STATE);
break;
}

retry_attempts = 0;
ESP_LOGI(TAG, "rx: %s", line); // debug incoming stratum messages
STRATUM_V1_parse(&stratum_api_v1_message, line);
free(line);
Expand Down

0 comments on commit 406dc5c

Please sign in to comment.