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:
13:d3571c244759
Parent:
11:0700755d64ae
Child:
15:371fbad587ed
--- a/HTTPServer.h	Tue Jun 06 01:39:39 2017 +0000
+++ b/HTTPServer.h	Wed Jun 07 05:53:36 2017 +0000
@@ -96,7 +96,6 @@
 #ifdef _DEBUG_HTTP_SERVER_H
         printf("dispatchRequest Invalid request\r\n");
 #endif
-        //close();
         return; //Invalid request
     }
     if( !meth.compare("GET") ) {
@@ -118,7 +117,6 @@
 #ifdef _DEBUG_HTTP_SERVER_H
         printf("dispatchRequest() Parse error\r\n");
 #endif
-        //close(); //Parse error
         return;
     }
 #ifdef _DEBUG_HTTP_SERVER_H
@@ -174,43 +172,37 @@
             break;
     }
     delete pHdlr;
-    // delete client;
-    // delete m_pTCPSocket;
 #ifdef _DEBUG_HTTP_SERVER_H
     printf("(dispatcherRequest)return\r\n");
 #endif
     return ;
 }
 
-void HTTPServerChild (void const *arg)
+void HTTPServerChild (TCPSocket* client)
 {
 #ifdef _DEBUG_HTTP_SERVER_H
     printf("HTTPServerChiled Start......\r\n");
 #endif
-    TCPSocket* client = (TCPSocket*)arg;
 
     for (;;) {
 #ifdef _DEBUG_HTTP_SERVER_H
-        printf("(HTTPServer.h<HTTPServerChild>)Connection from %s\r\n", client->get_address());
+        printf("(HTTPServer.h<HTTPServerChild>)Connection\r\n");
 #endif
         dispatchRequest(client);
 #ifdef _DEBUG_HTTP_SERVER_H
-        printf("(HTTPServer.h<HTTPServerChild>)Close %s\r\n", client->get_address());
+        printf("(HTTPServer.h<HTTPServerChild>)Close\r\n");
 #endif
         client->close();
-        //delete client;
         Thread::signal_wait(1);
     }
 }
 
-void HTTPServerCloser (void const *arg)
+void HTTPServerCloser (TCPSocket *client)
 {
-    TCPSocket *client = (TCPSocket*)arg;
-
     for (;;) {
         client->close();
 #ifdef _DEBUG_HTTP_SERVER_H
-        printf("Close %s\r\n", client->get_address());
+        printf("Close\r\n");
 #endif
         Thread::signal_wait(1);
     }
@@ -230,10 +222,10 @@
     TCPServer server(net);
     server.bind(port);
     server.listen();
-    // server.set_blocking(false);
 #ifdef _DEBUG_HTTP_SERVER_H
     printf("Wait for new connection...\r\n");
 #endif
+
     for (;;) {
 #ifdef _DEBUG_HTTP_SERVER_H
         printf("**Start Loop** \r\n");
@@ -244,7 +236,8 @@
                 if (threads[t]) {
                     threads[t]->signal_set(1);
                 } else {
-                    threads[t] = new Thread(HTTPServerChild, (void*)&clients[t], osPriorityNormal, 1024 * 3, NULL);
+                    threads[t] = new Thread(osPriorityNormal, 1024 * 3);
+                    threads[t]->start(callback(HTTPServerChild, &clients[t]));
                 }
 #ifdef _DEBUG_HTTP_SERVER_H
                 printf("Forked %d\r\n", t);
@@ -256,7 +249,8 @@
                 if (xthread) {
                     xthread->signal_set(1);
                 } else {
-                    xthread = new Thread(HTTPServerCloser, (void*)&xclient);
+                    xthread = new Thread;
+                    xthread->start(callback(HTTPServerCloser, &xclient));
                 }
 #ifdef _DEBUG_HTTP_SERVER_H
                 printf("Connection full\r\n");
@@ -271,7 +265,6 @@
                 if (t < 0) t = i; // next empty thread
             }
         }
-        // Thread::wait(100);
     }
 }
 #include "Handler/RPCHandler.h"