feat(lobby): implement bounded WebSocket sessions and countdown
This commit is contained in:
@@ -6,16 +6,19 @@
|
||||
|
||||
#define MAZE32_STATIC_CHUNK_SIZE 1024
|
||||
|
||||
static const char *TAG = "maze32_web";
|
||||
static const char *INDEX_PATH = "/littlefs/index.html.gz";
|
||||
static const char* TAG = "maze32_web";
|
||||
static const char* INDEX_PATH = "/littlefs/index.html.gz";
|
||||
|
||||
static esp_err_t send_index(httpd_req_t *request)
|
||||
{
|
||||
FILE *file = fopen(INDEX_PATH, "rb");
|
||||
static void preserve_static_context(void* context) {
|
||||
(void)context;
|
||||
}
|
||||
|
||||
static esp_err_t send_index(httpd_req_t* request) {
|
||||
FILE* file = fopen(INDEX_PATH, "rb");
|
||||
if (file == NULL) {
|
||||
ESP_LOGE(TAG, "Static asset is unavailable: %s", INDEX_PATH);
|
||||
httpd_resp_send_err(request, HTTPD_500_INTERNAL_SERVER_ERROR,
|
||||
"Static application is unavailable");
|
||||
"Приложение временно недоступно");
|
||||
return ESP_FAIL;
|
||||
}
|
||||
|
||||
@@ -45,18 +48,17 @@ static esp_err_t send_index(httpd_req_t *request)
|
||||
return result;
|
||||
}
|
||||
|
||||
static esp_err_t send_health(httpd_req_t *request)
|
||||
{
|
||||
const maze32_health_t *health = request->user_ctx;
|
||||
static esp_err_t send_health(httpd_req_t* request) {
|
||||
const maze32_health_t* health = request->user_ctx;
|
||||
char response[192];
|
||||
int length = snprintf(response, sizeof(response),
|
||||
"{\"status\":\"%s\",\"healthy\":%s,\"version\":\"%s\",\"errorCode\":%d}",
|
||||
maze32_health_state_name(health->state),
|
||||
maze32_health_is_healthy(health) ? "true" : "false",
|
||||
health->version, health->error_code);
|
||||
maze32_health_is_healthy(health) ? "true" : "false", health->version,
|
||||
health->error_code);
|
||||
if (length < 0 || (size_t)length >= sizeof(response)) {
|
||||
httpd_resp_send_err(request, HTTPD_500_INTERNAL_SERVER_ERROR,
|
||||
"Health response exceeded its fixed buffer");
|
||||
"Диагностический ответ слишком большой");
|
||||
return ESP_FAIL;
|
||||
}
|
||||
|
||||
@@ -65,16 +67,21 @@ static esp_err_t send_health(httpd_req_t *request)
|
||||
return httpd_resp_send(request, response, length);
|
||||
}
|
||||
|
||||
esp_err_t maze32_web_start(httpd_handle_t *server, maze32_health_t *health)
|
||||
{
|
||||
if (server == NULL || health == NULL) {
|
||||
esp_err_t maze32_web_start(httpd_handle_t* server, maze32_health_t* health,
|
||||
maze32_gateway_t* gateway) {
|
||||
if (server == NULL || health == NULL || gateway == NULL) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
httpd_config_t configuration = HTTPD_DEFAULT_CONFIG();
|
||||
configuration.max_uri_handlers = 8;
|
||||
configuration.max_open_sockets = 7;
|
||||
configuration.lru_purge_enable = true;
|
||||
configuration.max_uri_handlers = 9;
|
||||
configuration.max_open_sockets = 9;
|
||||
configuration.lru_purge_enable = false;
|
||||
configuration.recv_wait_timeout = 5;
|
||||
configuration.send_wait_timeout = 1;
|
||||
configuration.global_user_ctx = gateway;
|
||||
configuration.global_user_ctx_free_fn = preserve_static_context;
|
||||
configuration.close_fn = maze32_gateway_close_socket;
|
||||
|
||||
esp_err_t result = httpd_start(server, &configuration);
|
||||
if (result != ESP_OK) {
|
||||
|
||||
Reference in New Issue
Block a user