HttpServer Library for "mbed-os" which added a snapshot handler.

Dependents:   GR-PEACH-webcam GR-Boards_WebCamera GR-Boards_WebCamera GR-Boards_WebCamera

Fork of HttpServer_snapshot by Renesas

Revision:
17:6b7076372285
Parent:
16:16289b6ec82a
Child:
18:673d663a1ed7
--- a/HTTPServer.h	Thu Apr 11 09:24:27 2019 +0000
+++ b/HTTPServer.h	Wed Jul 03 11:23:12 2019 +0000
@@ -64,8 +64,8 @@
     int len = 0;
     for(int i = 0; i < maxLen - 1; i++) {
         ret = client->recv(p, 1);
-        if(!ret) {
-            break;
+        if(ret <= 0) {
+            return false;
         }
         if( (len > 1) && *(p-1)=='\r' && *p=='\n' ) {
             p--;
@@ -160,15 +160,15 @@
 #if (THREAD_MAX > 1) 
 static Thread *threads[THREAD_MAX];
 static bool soket_rady[THREAD_MAX];
-static TCPSocket clients[THREAD_MAX];
+static TCPSocket * clients[THREAD_MAX];
 
 static void HTTPServerChild (void* param)
 {
-    TCPSocket* client = &clients[(int)param];
     bool* p_rady = &soket_rady[(int)param];
 
     while (1) {
-        Thread::signal_wait(1);
+        ThisThread::flags_wait_all(1);
+        TCPSocket* client = clients[(int)param];
         dispatchRequest(client);
         client->close();
         *p_rady = true;
@@ -178,6 +178,7 @@
 void HTTPServerStart(NetworkInterface *net, int port = 80, osPriority priority = osPriorityNormal)
 {
     int i;
+    TCPSocket server;
 
     for (i = 0; i < THREAD_MAX; i++) {
         soket_rady[i] = true;
@@ -185,7 +186,7 @@
         threads[i]->start(callback(HTTPServerChild, (void *)i));
     }
 
-    TCPServer server(net);
+    server.open(net);
     server.bind(port);
     server.listen();
     http_server_debug_print("Wait for new connection...\r\n");
@@ -203,11 +204,11 @@
             ThisThread::sleep_for(5);
         }
 
-        http_server_debug_print("**Start Loop** \r\n");
-        if(server.accept(&clients[i])==0) {
+        clients[i] = server.accept();
+        if (clients[i] != NULL) {
             // fork child process
             soket_rady[i] = false;
-            threads[i]->signal_set(1);
+            threads[i]->flags_set(1);
         }
     }
 }
@@ -216,20 +217,21 @@
 
 void HTTPServerStart(NetworkInterface *net, int port = 80, osPriority priority = osPriorityNormal)
 {
-    TCPSocket client;
+    TCPSocket server;
+    TCPSocket * p_client;
 
     (void)priority;
 
-    TCPServer server(net);
+    server.open(net);
     server.bind(port);
     server.listen();
     http_server_debug_print("Wait for new connection...\r\n");
 
     while (1) {
-        http_server_debug_print("**Start Loop** \r\n");
-        if (server.accept(&client) == 0) {
-            dispatchRequest(&client);
-            client.close();
+        p_client = server.accept();
+        if (p_client != NULL) {
+            dispatchRequest(p_client);
+            p_client->close();
         }
     }
 }