diff options
Diffstat (limited to 'main/cvm_server.c')
| -rw-r--r-- | main/cvm_server.c | 23 |
1 files changed, 4 insertions, 19 deletions
diff --git a/main/cvm_server.c b/main/cvm_server.c index a4804d2..10af956 100644 --- a/main/cvm_server.c +++ b/main/cvm_server.c | |||
| @@ -31,9 +31,6 @@ static void publish_announcements_via_ws(esp_tls_t *tls); | |||
| 31 | #define CVM_WS_BUF_SIZE 8192 | 31 | #define CVM_WS_BUF_SIZE 8192 |
| 32 | #define CVM_MAX_RESPONSE_SIZE 4096 | 32 | #define CVM_MAX_RESPONSE_SIZE 4096 |
| 33 | #define CVM_RECONNECT_DELAY_MS 5000 | 33 | #define CVM_RECONNECT_DELAY_MS 5000 |
| 34 | #define CVM_WS_READ_TIMEOUT_MS 1000 | ||
| 35 | #define CVM_WS_PING_INTERVAL_S 30 | ||
| 36 | #define CVM_WS_MAX_CONSECUTIVE_TIMEOUTS 65 | ||
| 37 | 34 | ||
| 38 | static char *parse_ws_text_frame(const uint8_t *buf, int len) | 35 | static char *parse_ws_text_frame(const uint8_t *buf, int len) |
| 39 | { | 36 | { |
| @@ -557,19 +554,14 @@ static void cvm_relay_task(void *arg) | |||
| 557 | return; | 554 | return; |
| 558 | } | 555 | } |
| 559 | 556 | ||
| 560 | int64_t last_ping_time = (int64_t)esp_timer_get_time() / 1000000; | ||
| 561 | int consecutive_timeouts = 0; | 557 | int consecutive_timeouts = 0; |
| 562 | |||
| 563 | while (g_running) { | 558 | while (g_running) { |
| 564 | int rlen = esp_tls_conn_read(tls, buf, CVM_WS_BUF_SIZE - 1); | 559 | int rlen = esp_tls_conn_read(tls, buf, CVM_WS_BUF_SIZE - 1); |
| 565 | if (rlen < 0) { | 560 | if (rlen < 0) { |
| 566 | consecutive_timeouts++; | 561 | ESP_LOGW(TAG, "Read error on %s (rlen=%d)", relay_url, rlen); |
| 567 | if (consecutive_timeouts >= CVM_WS_MAX_CONSECUTIVE_TIMEOUTS) { | 562 | break; |
| 568 | ESP_LOGW(TAG, "Read timeout on %s (%d consecutive)", relay_url, consecutive_timeouts); | 563 | } |
| 569 | break; | 564 | if (rlen == 0) { |
| 570 | } | ||
| 571 | } else if (rlen == 0) { | ||
| 572 | ESP_LOGW(TAG, "Connection closed by %s", relay_url); | ||
| 573 | break; | 565 | break; |
| 574 | } else { | 566 | } else { |
| 575 | consecutive_timeouts = 0; | 567 | consecutive_timeouts = 0; |
| @@ -591,13 +583,6 @@ static void cvm_relay_task(void *arg) | |||
| 591 | } | 583 | } |
| 592 | } | 584 | } |
| 593 | 585 | ||
| 594 | int64_t now = (int64_t)esp_timer_get_time() / 1000000; | ||
| 595 | if (now - last_ping_time >= CVM_WS_PING_INTERVAL_S) { | ||
| 596 | uint8_t ping[2] = {0x89, 0x00}; | ||
| 597 | esp_tls_conn_write(tls, ping, 2); | ||
| 598 | last_ping_time = now; | ||
| 599 | ESP_LOGD(TAG, "Sent WS keepalive ping"); | ||
| 600 | } | ||
| 601 | } | 586 | } |
| 602 | 587 | ||
| 603 | free(buf); | 588 | free(buf); |