Added more convenient functions for sending data to websocket

This commit is contained in:
Martin Valik
2021-03-10 11:20:04 +01:00
parent 502e132e5d
commit 1f451a4a77
2 changed files with 121 additions and 0 deletions

View File

@@ -1603,6 +1603,11 @@ typedef struct httpd_ws_frame {
size_t len; /*!< Length of the WebSocket data */
} httpd_ws_frame_t;
/**
* @brief Transfer complete callback
*/
typedef void (*transfer_complete_cb)(esp_err_t err, int socket, void *arg);
/**
* @brief Receive and parse a WebSocket frame
*
@@ -1663,6 +1668,35 @@ esp_err_t httpd_ws_send_frame_async(httpd_handle_t hd, int fd, httpd_ws_frame_t
*/
httpd_ws_client_info_t httpd_ws_get_fd_info(httpd_handle_t hd, int fd);
/**
* @brief Sends data to to specified websocket synchronously
*
* @param[in] handle Server instance data
* @param[in] socket Socket descriptor
* @param[in] frame Websocket frame
* @return
* - ESP_OK : On successful
* - ESP_FAIL : When socket errors occurs
* - ESP_ERR_NO_MEM : Unable to allocate memory
*/
esp_err_t httpd_ws_send_data(httpd_handle_t handle, int socket, httpd_ws_frame_t *frame);
/**
* @brief Sends data to to specified websocket asynchronously
*
* @param[in] handle Server instance data
* @param[in] socket Socket descriptor
* @param[in] frame Websocket frame
* @param[in] callback Callback invoked after sending data
* @param[in] arg User data passed to provided callback
* @return
* - ESP_OK : On successful
* - ESP_FAIL : When socket errors occurs
* - ESP_ERR_NO_MEM : Unable to allocate memory
*/
esp_err_t httpd_ws_send_data_async(httpd_handle_t handle, int socket, httpd_ws_frame_t *frame,
transfer_complete_cb callback, void *arg);
#endif /* CONFIG_HTTPD_WS_SUPPORT */
/** End of WebSocket related stuff
* @}