Changes made for RPC

Revision:
11:3943841e1798
Parent:
9:c2a1462b9b71
Child:
12:ba81cc117fb6
--- a/HTTPServer.cpp	Sun Jun 02 00:37:38 2013 +0000
+++ b/HTTPServer.cpp	Sun Jun 02 22:59:51 2013 +0000
@@ -1,7 +1,7 @@
 #include "mbed.h"
 #include "HTTPServer.h"
 
-#define _DEBUG      1
+#define _DEBUG      0
 
 #ifdef _DEBUG
 DigitalOut led1(LED1);
@@ -45,7 +45,7 @@
 {
     char echoHeader[256];
     tcp.set_blocking(true, 1500);
-    sprintf(echoHeader,"HTTP/1.1 404 Fail\r\nContent-Length: %d\r\nContent-Type: text/html\r\nServer: mbed embedded\r\n\n\r",strlen(szStdErrorPage));
+    sprintf(echoHeader,"HTTP/1.0 404 Fail\r\nConnection: close\r\nContent-Length: %d\r\nContent-Type: text/html\r\nServer: mbed embedded\r\n\n\r",strlen(szStdErrorPage));
     tcp.send(echoHeader, strlen(echoHeader));
     tcp.send((char*)szStdErrorPage, strlen(szStdErrorPage));
 }
@@ -64,7 +64,10 @@
 
     INFO("Connecting to network...");
     //  Try join the network
-    while(!m_wifly.connect());
+    while(!m_wifly.connect()) {
+        INFO("Failed to connect. Trying again\n");
+        m_wifly.reset();
+    }
     INFO("connected\n");
 
     // check if the start member was called already once
@@ -150,20 +153,31 @@
         //   a new connection was received
         INFO("Client (IP=%s) is connected !\n", Clnt.get_address());
         //  Start the main connection thread
-#ifdef _DEBUG
-        led3 = 1;
-        led2 = 1;
-#endif
-        HTTPConnection con;
-        int c = con.poll();
-        if (c == 0) {
-            //  Handle the request
-            HandleRequest(con.m_Msg, Clnt);
-        }
-#ifdef _DEBUG
-        led2 = 0;
-        led3 = 0;
-#endif
+//        while(1) {
+            
+    #ifdef _DEBUG
+            led3 = 1;
+            led2 = 1;
+    #endif
+            HTTPConnection con;
+            int c = con.poll();
+            if (c == 0) {
+                //  Handle the request
+                HandleRequest(con.m_Msg, Clnt);
+                INFO("Closing connection.\n");
+//                if (!m_wifly.close()) {
+//                    ERR("Failed to close connection !\n");
+//                }
+            }
+            if (c == -1) {
+                // No more data available or error
+ //               break;
+            }
+    #ifdef _DEBUG
+            led2 = 0;
+            led3 = 0;
+    #endif
+//        }
     }
     
     INFO("Leaving polling thread");