mirror of
https://github.com/rstrouse/ESPSomfy-RTS.git
synced 2026-10-31 22:02:17 +01:00
feat: edit ops and the reads their forms need, for socket protocol 2
The edit routes become ops 26-44 (addRoom ... groupSortOrder): ProtoEdits turns an op's payload into the route's request, full names and real booleans, and loop() applies it with applyModelEdit() as the route does. The reply goes to the client that sent it, with an add's new id, or the route's reason and a shade's validation code; the HTTP routes keep sending requestResult. getNextRoom, getNextShade, getNextGroup and groupOptions (45-48) are answered by loop() from the shade model, through a new LoopQueue item. Messages that arrive in pieces, a frame over one TCP segment or several frames, are put back together by ProtoAssembly: one at a time across clients, up to 4 KB, in a buffer held only while one is on its way. A message in pieces is now told from its first frame's opcode, which also stops a fragmented message's last frame drawing a second reply. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
ea973809e2
commit
77237111ea
22 changed files with 851 additions and 22 deletions
47
src/ProtoAssembly.cpp
Normal file
47
src/ProtoAssembly.cpp
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "ProtoAssembly.h"
|
||||
|
||||
void MessageAssembler::free() {
|
||||
::free(this->buf);
|
||||
this->buf = nullptr;
|
||||
this->len = 0;
|
||||
this->owner = 0;
|
||||
}
|
||||
void MessageAssembler::drop(uint32_t clientId) {
|
||||
if(this->owner == clientId) this->free();
|
||||
if(this->stalled == clientId) this->stalled = 0;
|
||||
}
|
||||
assembly_t MessageAssembler::add(const proto_piece_t &piece, uint32_t now) {
|
||||
if(piece.first) {
|
||||
if(this->stalled == piece.clientId) this->stalled = 0;
|
||||
if(this->owner && this->owner != piece.clientId) {
|
||||
if(now - this->startedAt < PROTO_ASSEMBLY_TIMEOUT_MS) return assembly_t::busy;
|
||||
// A message that stalled gives the buffer up after a while.
|
||||
this->stalled = this->owner;
|
||||
}
|
||||
this->free();
|
||||
if(!piece.text) return assembly_t::notText;
|
||||
this->buf = static_cast<char *>(malloc(this->limit + 1));
|
||||
if(!this->buf) return assembly_t::noMemory;
|
||||
this->owner = piece.clientId;
|
||||
this->startedAt = now;
|
||||
}
|
||||
else if(this->owner != piece.clientId) {
|
||||
if(this->stalled == piece.clientId) {
|
||||
this->stalled = 0;
|
||||
return assembly_t::timedOut;
|
||||
}
|
||||
// The rest of a message that was already answered.
|
||||
return assembly_t::ignored;
|
||||
}
|
||||
if(this->len + piece.len > this->limit) {
|
||||
this->free();
|
||||
return assembly_t::tooLarge;
|
||||
}
|
||||
memcpy(this->buf + this->len, piece.data, piece.len);
|
||||
this->len += piece.len;
|
||||
if(!piece.last) return assembly_t::more;
|
||||
this->buf[this->len] = '\0';
|
||||
return assembly_t::complete;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue