mirror of
https://github.com/espressif/esp-idf.git
synced 2025-08-18 15:47:13 +00:00
http_server: WebSocket server to set flag in transmitted messages by default
Add logic to set `FIN` flag automatically for transmitted WS frames, but if `fragmented` option set indicating an expert/manual mode, then the `FIN` flag is set according to the `final` option.
This commit is contained in:
@@ -32,6 +32,7 @@ static const char *TAG="httpd_ws";
|
||||
* Bit masks for WebSocket frames.
|
||||
* Please refer to RFC6455 Section 5.2 for more details.
|
||||
*/
|
||||
#define HTTPD_WS_CONTINUE 0x00U
|
||||
#define HTTPD_WS_FIN_BIT 0x80U
|
||||
#define HTTPD_WS_OPCODE_BITS 0x0fU
|
||||
#define HTTPD_WS_MASK_BIT 0x80U
|
||||
@@ -279,7 +280,8 @@ esp_err_t httpd_ws_send_frame_async(httpd_handle_t hd, int fd, httpd_ws_frame_t
|
||||
/* Prepare Tx buffer - maximum length is 14, which includes 2 bytes header, 8 bytes length, 4 bytes mask key */
|
||||
uint8_t tx_len = 0;
|
||||
uint8_t header_buf[10] = {0 };
|
||||
header_buf[0] |= frame->final ? HTTPD_WS_FIN_BIT : 0; /* Final (FIN) bit */
|
||||
/* Set the `FIN` bit by default if message is not fragmented. Else, set it as per the `final` field */
|
||||
header_buf[0] |= (!frame->fragmented) ? HTTPD_WS_FIN_BIT : (frame->final? HTTPD_WS_FIN_BIT: HTTPD_WS_CONTINUE);
|
||||
header_buf[0] |= frame->type; /* Type (opcode): 4 bits */
|
||||
|
||||
if (frame->len <= 125) {
|
||||
@@ -381,4 +383,4 @@ esp_err_t httpd_ws_get_frame_type(httpd_req_t *req)
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
#endif /* CONFIG_HTTPD_WS_SUPPORT */
|
||||
#endif /* CONFIG_HTTPD_WS_SUPPORT */
|
||||
|
Reference in New Issue
Block a user