8000 ifdef some ESP8266 specific stuff · robokoding/arduinoWebSockets@d5c3e17 · GitHub
[go: up one dir, main page]

Skip to content
8000

Commit d5c3e17

Browse files
committed
ifdef some ESP8266 specific stuff
rework readWait
1 parent 259ea32 commit d5c3e17

File tree

2 files changed

+20
-12
lines changed

2 files changed

+20
-12
lines changed

src/WebSockets.cpp

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ extern "C" {
2828
#include "libb64/cencode.h"
2929
}
3030

31+
#ifdef ESP8266
3132
#include <Hash.h>
33+
#endif
3234

3335
/**
3436
*
@@ -284,8 +286,11 @@ void WebSockets::handleWebsocket(WSclient_t * client) {
284286
*/
285287
String WebSockets::acceptKey(String clientKey) {
286288
uint8_t sha1HashBin[20] = { 0 };
289+
#ifdef ESP8266
287290
sha1(clientKey + "258EAFA5-E914-47DA-95CA-C5AB0DC85B11", &sha1HashBin[0]);
288-
291+
#else
292+
#error todo implement sha1 for AVR
293+
#endif
289294
String key = base64_encode(sha1HashBin, 20);
290295
key.trim();
291296

@@ -327,19 +332,20 @@ bool WebSockets::readWait(WSclient_t * client, uint8_t *out, size_t n) {
327332

328333
while(n > 0) {
329334
if(!client->tcp.connected()) {
330-
DEBUG_WEBSOCKETS("[readWait] Receive not connected - 1!\n");
335+
DEBUG_WEBSOCKETS("[readWait] not connected!\n");
331336
return false;
332337
}
333-
while(!client->tcp.available()) {
334-
if(!client->tcp.connected()) {
335-
DEBUG_WEBSOCKETS("[readWait] Receive not connected - 2!\n");
336-
return false;
337-
}
338-
if((millis() - t) > WEBSOCKETS_TCP_TIMEOUT) {
339-
DEBUG_WEBSOCKETS("[readWait] Receive TIMEOUT!\n");
340-
return false;
341-
}
338+
339+
if((millis() - t) > WEBSOCKETS_TCP_TIMEOUT) {
340+
DEBUG_WEBSOCKETS("[readWait] receive TIMEOUT!\n");
341+
return false;
342+
}
343+
344+
if(!client->tcp.available()) {
345+
#ifdef ESP8266
342346
delay(0);
347+
#endif
348+
continue;
343349
}
344350

345351
len = client->tcp.read((uint8_t*) out, n);
@@ -351,7 +357,9 @@ bool WebSockets::readWait(WSclient_t * client, uint8_t *out, size_t n) {
351357
} else {
352358
//DEBUG_WEBSOCKETS("Receive %d left %d!\n", len, n);
353359
}
360+
#ifdef ESP8266
354361
delay(0);
362+
#endif
355363
}
356364
return true;
357365
}

src/WebSocketsServer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,7 @@ void WebSocketsServer::handleHeader(WSclient_t * client) {
458458
client->status = WSC_CONNECTED;
459459

460460
client->tcp.write("HTTP/1.1 101 Switching Protocols\r\n"
461-
"Server: ESP8266-WebSocketsServer\r\n"
461+
"Server: arduino-WebSocketsServer\r\n"
462462
"Upgrade: websocket\r\n"
463463
"Connection: Upgrade\r\n"
464464
"Sec-WebSocket-Version: 13\r\n"

0 commit comments

Comments
 (0)
0