HTTP Server, WebSocket support

Fork of HTTPD by Suga koubou

Revision:
1:b724fdb741e7
Parent:
0:d18dff347122
--- a/HTTPD.h	Wed Nov 13 01:58:04 2013 +0000
+++ b/HTTPD.h	Thu Jun 15 20:17:24 2017 +0000
@@ -21,13 +21,14 @@
 
 #include "mbed.h"
 #include "rtos.h"
-#include "EthernetInterface.h"
+#include "NetworkStack.h"
+#include "EthInterface.h"
 #include "CBuffer.h"
 
-//#define DEBUG
+#define DEBUG
 
 #define HTTPD_PORT 80
-#define HTTPD_MAX_CLIENTS 2
+#define HTTPD_MAX_CLIENTS 5
 #define HTTPD_KEEPALIVE 10
 #define HTTPD_TIMEOUT 15000
 #define HTTPD_MAX_HANDLES 10
@@ -75,7 +76,7 @@
 
     struct STATE {
         Thread *thread;
-        TCPSocketConnection *client;
+        TCPSocket *client;
         volatile Request req;
         volatile Mode mode;
         CircBuffer <char>*buf;
@@ -97,7 +98,7 @@
 
     HTTPD ();
     
-    int start (int port = HTTPD_PORT);
+    int start (NetworkStack *ns, int port = HTTPD_PORT);
 
     // --- HTTPD_req.cpp ---
     void httpdError (int id, int err);
@@ -109,7 +110,14 @@
     char *getUri (int id);
     char *getFilename (int id);
     char *getQueryString (int id);
+    
+    TCPSocket *getClientSocket(int id) {
+        if (id >= HTTPD_MAX_CLIENTS) return NULL;
+        return _state[id].client;
+    }
     int send (int id, const char *body, int len, const char *header = NULL);
+    int sendstr (int id, const char *buf);
+    int hprintf(int id, const char* format, ...);
     int receive (int id, char *buf, int len);
     int attach (const char *uri, const char *dir);
     int attach (const char *uri, void (*funcCgi)(int id));
@@ -124,7 +132,9 @@
 private :
     static HTTPD *_inst;
     Thread *_daemon;
-    TCPSocketServer _server;
+    TCPServer _server;
+    
+    NetworkStack *m_ns;
 
 #ifdef HTTPD_ENABLE_CLOSER
     struct STATE _state[HTTPD_MAX_CLIENTS + 1];
@@ -140,7 +150,7 @@
 
     int _handler_count;
 
-    static void daemon (void const *arg);
+    static void daemon ();
     static void child (void const *arg);
     static void closer (void const *arg);