feat: implement WebSocket synchronization and HTTP recovery

This commit is contained in:
2026-08-28 23:33:14 +03:00
parent 95b3450317
commit 03b283f892
8 changed files with 524 additions and 13 deletions
+33
View File
@@ -0,0 +1,33 @@
#pragma once
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include "application.h"
enum {
kWebSocketFrameCapacity = 192,
kWebSocketHelloTimeoutMs = 5000,
};
typedef struct {
int client_id;
uint8_t session_index;
bool active;
bool authenticated;
uint64_t opened_ms;
} sync_connection_t;
typedef struct { application_t *application; sync_connection_t connections[kSessionCapacity]; } sync_service_t;
typedef bool (*sync_send_fn)(void *context, int client_id, const char *payload, size_t length);
void sync_service_init(sync_service_t *service, application_t *application);
bool sync_service_open(sync_service_t *service, int client_id, uint64_t now_ms);
void sync_service_close(sync_service_t *service, int client_id);
bool sync_service_receive(sync_service_t *service, int client_id, const char *frame, size_t frame_length,
uint64_t now_ms, char output[kStateMessageCapacity], size_t *output_length,
bool *state_changed, bool *close_client);
void sync_service_expire(sync_service_t *service, uint64_t now_ms, int closed_clients[kSessionCapacity],
size_t *closed_count);
void sync_service_broadcast(sync_service_t *service, sync_send_fn send, void *context);