Skip to content

Commit

Permalink
Added a semi-workaround for recevie issues i've been having. This sho…
Browse files Browse the repository at this point in the history
…uld be further invested. Maybe sync sockets? read wrapper? (TODO)
  • Loading branch information
gilmaimon committed Aug 1, 2019
1 parent 45089ed commit a3da335
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion src/websockets_endpoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,26 @@ namespace internals {
}

Header readHeaderFromSocket(network::TcpClient& socket) {
int retriesLeft = 10;

uint32_t numRead = 0;
do {
--retriesLeft;
Header header;
header.payload = 0;
numRead = socket.read(reinterpret_cast<uint8_t*>(&header), 2);

if(numRead == 2) {
return header;
}
} while(retriesLeft > 0);

// TODO: handle bad receives and wrap `read` with fail-proof wrappers
Serial.println("This is a nasty internal error in ArduinoWebsockets! Sorry.");
Header header;
header.payload = 0;
socket.read(reinterpret_cast<uint8_t*>(&header), 2);
header.fin = 0;
header.opcode = 0;
return header;
}

Expand Down

0 comments on commit a3da335

Please sign in to comment.