forked from espressif/esp-protocols
feat(websocket): allow updating reconnect timeout for retry backoffs
This commit is contained in:
@ -1278,6 +1278,43 @@ esp_err_t esp_websocket_client_set_ping_interval_sec(esp_websocket_client_handle
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
int esp_websocket_client_get_reconnect_timeout(esp_websocket_client_handle_t client)
|
||||
{
|
||||
if (client == NULL) {
|
||||
ESP_LOGW(TAG, "Client was not initialized");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!client->config->auto_reconnect) {
|
||||
ESP_LOGW(TAG, "Automatic reconnect is disabled");
|
||||
return -1;
|
||||
}
|
||||
|
||||
return client->wait_timeout_ms;
|
||||
}
|
||||
|
||||
esp_err_t esp_websocket_client_set_reconnect_timeout(esp_websocket_client_handle_t client, int reconnect_timeout_ms)
|
||||
{
|
||||
if (client == NULL) {
|
||||
ESP_LOGW(TAG, "Client was not initialized");
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
if (reconnect_timeout_ms <= 0) {
|
||||
ESP_LOGW(TAG, "Invalid reconnect timeout");
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
if (!client->config->auto_reconnect) {
|
||||
ESP_LOGW(TAG, "Automatic reconnect is disabled");
|
||||
return ESP_ERR_INVALID_STATE;
|
||||
}
|
||||
|
||||
client->wait_timeout_ms = reconnect_timeout_ms;
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t esp_websocket_register_events(esp_websocket_client_handle_t client,
|
||||
esp_websocket_event_id_t event,
|
||||
esp_event_handler_t event_handler,
|
||||
|
@ -416,6 +416,29 @@ size_t esp_websocket_client_get_ping_interval_sec(esp_websocket_client_handle_t
|
||||
*/
|
||||
esp_err_t esp_websocket_client_set_ping_interval_sec(esp_websocket_client_handle_t client, size_t ping_interval_sec);
|
||||
|
||||
/**
|
||||
* @brief Get the next reconnect timeout for client. Returns -1 when client is not initialized or automatic reconnect is disabled.
|
||||
*
|
||||
* @param[in] client The client
|
||||
*
|
||||
* @return Reconnect timeout in msec
|
||||
*/
|
||||
int esp_websocket_client_get_reconnect_timeout(esp_websocket_client_handle_t client);
|
||||
|
||||
/**
|
||||
* @brief Set next reconnect timeout for client.
|
||||
*
|
||||
* Notes:
|
||||
* - Changing this value when reconnection delay is already active does not immediately affect the active delay and may have unexpected result.
|
||||
* - Good place to change this value is when handling WEBSOCKET_EVENT_DISCONNECTED or WEBSOCKET_EVENT_ERROR events.
|
||||
*
|
||||
* @param[in] client The client
|
||||
* @param[in] reconnect_timeout_ms The new timeout
|
||||
*
|
||||
* @return esp_err_t
|
||||
*/
|
||||
esp_err_t esp_websocket_client_set_reconnect_timeout(esp_websocket_client_handle_t client, int reconnect_timeout_ms);
|
||||
|
||||
/**
|
||||
* @brief Register the Websocket Events
|
||||
*
|
||||
|
Reference in New Issue
Block a user