Send binary WebSocket frames in one write

This commit is contained in:
2026-09-08 23:52:00 +02:00
parent 042499e4d6
commit 60d9c54bb4
10 changed files with 334 additions and 8 deletions
+8
View File
@@ -20,6 +20,7 @@ from serial_headers import SERIAL_HEADERS
HEADERS.update(SERIAL_HEADERS)
HEADERS["esp_http_server.h"] += """
#define HTTPD_SOCK_ERR_FAIL -1
#define ESP_ERR_HTTPD_INVALID_REQ 0x200
#define ESP_ERR_HTTPD_RESULT_TRUNC 0x201
#define ESP_ERR_HTTPD_RESP_HDR 0x202
@@ -35,6 +36,7 @@ HEADERS["esp_httpd_priv.h"] = """#pragma once
#include "esp_http_server.h"
static inline void *httpd_os_thread_handle(void) { return (void *)1; }
struct sock_db { int fd; bool for_async_req, ws_close; uint64_t lru_counter;
void *ctx; int (*send_fn)(httpd_handle_t, int, const char *, size_t, int);
int (*pending_fn)(httpd_handle_t, int);
bool ws_handshake_done; esp_err_t (*ws_handler)(httpd_req_t *);
bool ws_control_frames; void *ws_user_ctx; char pending_data[128]; size_t pending_len; };
@@ -44,6 +46,12 @@ struct httpd_req_aux { struct sock_db *sd; char *scratch; size_t scratch_cur_siz
struct httpd_data { struct { unsigned max_resp_headers, max_uri_handlers, max_open_sockets; void *uri_match_fn; } config;
struct { void *handle; } hd_td; struct httpd_req_aux hd_req_aux; struct sock_db *hd_sd;
httpd_uri_t **hd_calls; };
static inline struct sock_db *httpd_sess_get(httpd_handle_t h, int fd) {
struct httpd_data *hd = h;
for (unsigned i = 0; i < hd->config.max_open_sockets; ++i)
if (hd->hd_sd[i].fd == fd) return &hd->hd_sd[i];
return NULL;
}
esp_err_t httpd_ws_respond_server_handshake(httpd_req_t *, const char *);
"""