Merge pull request #61 from cjkas/fix/socket-buffer-4k

fix: make the socket buffer big enough for the largest event
This commit is contained in:
cjkas 2026-10-17 23:36:19 +02:00 • committed by GitHub
commit e06ee3a060
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 19 additions and 12 deletions

View file

@ -337,6 +337,9 @@ bool Transceiver::receive(somfy_rx_t *rx) {
return false;
}
void Transceiver::emitFrame(somfy_frame_t *frame, somfy_rx_t *rx) {
// The largest socket event: every pulse as up to 10 digits and a comma,
// plus about 300 bytes of fields and framing.
static_assert(MAX_TIMINGS * 11 + 512 <= MAX_SOCK_RESPONSE, "remoteFrame can outgrow the socket buffer");
if(sockEmit.activeClients(ROOM_EMIT_FRAME) > 0) {
JsonSockEvent *json = sockEmit.beginEmit("remoteFrame");
json->beginObject();

View file

@ -49,7 +49,6 @@ static void removeClient(uint32_t asyncId) {
if(slots[i].asyncId == asyncId) slots[i].asyncId = 0;
}
#define MAX_SOCK_RESPONSE 2048
static char g_response[MAX_SOCK_RESPONSE];
bool room_t::isJoined(uint8_t num) {

View file

@ -5,6 +5,10 @@
#define SOCK_MAX_ROOMS 1
#define ROOM_EMIT_FRAME 0
// The buffer every socket event is formatted into. An event that doesn't
// fit is logged and not sent, so the largest one has to fit: see remoteFrame
// in Transceiver.cpp.
#define MAX_SOCK_RESPONSE 4096
struct room_t {
uint8_t clients[5] = {255, 255, 255, 255, 255};