HTTP Server, WebSocket support

Fork of HTTPD by Suga koubou

Revision:
1:b724fdb741e7
Parent:
0:d18dff347122
--- a/HTTPD_ws.cpp	Wed Nov 13 01:58:04 2013 +0000
+++ b/HTTPD_ws.cpp	Thu Jun 15 20:17:24 2017 +0000
@@ -124,7 +124,7 @@
         for (i = 0; i < _state[id].length; i ++) {
             if (_state[id].buf->dequeue(&pong[i + 2]) == false) break;
         }
-        _state[id].client->send_all(pong, _state[id].length + 2);
+        _state[id].client->send(pong, _state[id].length + 2);
         }
         break;
     case 0x0a: // pong
@@ -143,22 +143,22 @@
     DBG("websocket accept: %d\r\n", id);
 
     strcpy(buf, "HTTP/1.1 101 Switching Protocols\r\n");
-    _state[id].client->send_all(buf, strlen(buf));
+    _state[id].client->send(buf, strlen(buf));
     strcpy(buf, "Upgrade: websocket\r\n");
-    _state[id].client->send_all(buf, strlen(buf));
+    _state[id].client->send(buf, strlen(buf));
     strcpy(buf, "Connection: Upgrade\r\n");
-    _state[id].client->send_all(buf, strlen(buf));
+    _state[id].client->send(buf, strlen(buf));
 
     strcpy(buf, "Sec-WebSocket-Accept: ");
-    _state[id].client->send_all(buf, strlen(buf));
+    _state[id].client->send(buf, strlen(buf));
     strcpy(buf, _state[id].websocket_key);
     strcat(buf, "258EAFA5-E914-47DA-95CA-C5AB0DC85B11");
     sha1(buf, strlen(buf), buf2);
     base64encode(buf2, 20, buf, sizeof(buf));
-    _state[id].client->send_all(buf, strlen(buf));
+    _state[id].client->send(buf, strlen(buf));
     strcpy(buf, "\r\n\r\n");
-    _state[id].client->send_all(buf, strlen(buf));
-    _state[id].client->set_blocking(true, HTTPD_TIMEOUT * 100);
+    _state[id].client->send(buf, strlen(buf));
+    //_state[id].client->set_blocking(true, HTTPD_TIMEOUT * 100);
     return 0;
 }
 
@@ -179,7 +179,7 @@
         memcpy(&tmp[i], mask, 4);
         i += 4;
     }
-    r = httpd->_state[id].client->send_all(tmp, i);
+    r = httpd->_state[id].client->send(tmp, i);
 
     if (r >= 0) {
         if (mask) {
@@ -187,9 +187,9 @@
             for (i = 0; i < len; i ++) {
                 tmp2[i] = buf[i] ^ mask[i & 0x03];
             }
-            r = httpd->_state[id].client->send_all(tmp2, len);
+            r = httpd->_state[id].client->send(tmp2, len);
         } else {
-            r = httpd->_state[id].client->send_all((char*)buf, len);
+            r = httpd->_state[id].client->send((char*)buf, len);
         }
     }
     return r;