ifdef some ESP8266 specific stuff

rework readWait
This commit is contained in:
Markus Sattler
2015-05-24 18:00:35 +02:00
parent 259ea32850
commit d5c3e17a25
2 changed files with 20 additions and 12 deletions

View File

@ -28,7 +28,9 @@ extern "C" {
#include "libb64/cencode.h" #include "libb64/cencode.h"
} }
#ifdef ESP8266
#include <Hash.h> #include <Hash.h>
#endif
/** /**
* *
@ -284,8 +286,11 @@ void WebSockets::handleWebsocket(WSclient_t * client) {
*/ */
String WebSockets::acceptKey(String clientKey) { String WebSockets::acceptKey(String clientKey) {
uint8_t sha1HashBin[20] = { 0 }; uint8_t sha1HashBin[20] = { 0 };
#ifdef ESP8266
sha1(clientKey + "258EAFA5-E914-47DA-95CA-C5AB0DC85B11", &sha1HashBin[0]); sha1(clientKey + "258EAFA5-E914-47DA-95CA-C5AB0DC85B11", &sha1HashBin[0]);
#else
#error todo implement sha1 for AVR
#endif
String key = base64_encode(sha1HashBin, 20); String key = base64_encode(sha1HashBin, 20);
key.trim(); key.trim();
@ -327,19 +332,20 @@ bool WebSockets::readWait(WSclient_t * client, uint8_t *out, size_t n) {
while(n > 0) { while(n > 0) {
if(!client->tcp.connected()) { if(!client->tcp.connected()) {
DEBUG_WEBSOCKETS("[readWait] Receive not connected - 1!\n"); DEBUG_WEBSOCKETS("[readWait] not connected!\n");
return false; return false;
} }
while(!client->tcp.available()) {
if(!client->tcp.connected()) { if((millis() - t) > WEBSOCKETS_TCP_TIMEOUT) {
DEBUG_WEBSOCKETS("[readWait] Receive not connected - 2!\n"); DEBUG_WEBSOCKETS("[readWait] receive TIMEOUT!\n");
return false; return false;
} }
if((millis() - t) > WEBSOCKETS_TCP_TIMEOUT) {
DEBUG_WEBSOCKETS("[readWait] Receive TIMEOUT!\n"); if(!client->tcp.available()) {
return false; #ifdef ESP8266
}
delay(0); delay(0);
#endif
continue;
} }
len = client->tcp.read((uint8_t*) out, n); len = client->tcp.read((uint8_t*) out, n);
@ -351,7 +357,9 @@ bool WebSockets::readWait(WSclient_t * client, uint8_t *out, size_t n) {
} else { } else {
//DEBUG_WEBSOCKETS("Receive %d left %d!\n", len, n); //DEBUG_WEBSOCKETS("Receive %d left %d!\n", len, n);
} }
#ifdef ESP8266
delay(0); delay(0);
#endif
} }
return true; return true;
} }

View File

@ -458,7 +458,7 @@ void WebSocketsServer::handleHeader(WSclient_t * client) {
client->status = WSC_CONNECTED; client->status = WSC_CONNECTED;
client->tcp.write("HTTP/1.1 101 Switching Protocols\r\n" client->tcp.write("HTTP/1.1 101 Switching Protocols\r\n"
"Server: ESP8266-WebSocketsServer\r\n" "Server: arduino-WebSocketsServer\r\n"
"Upgrade: websocket\r\n" "Upgrade: websocket\r\n"
"Connection: Upgrade\r\n" "Connection: Upgrade\r\n"
"Sec-WebSocket-Version: 13\r\n" "Sec-WebSocket-Version: 13\r\n"