Andrew Boyson / web

Dependents:   oldheating gps motorhome heating

Files at this revision

API Documentation at this revision

Comitter:
andrewboyson
Date:
Sun Sep 01 18:12:48 2019 +0000
Parent:
128:fc9708e1d17c
Child:
130:9a5b8fe308f1
Commit message:
Tidied up connection checks

Changed in this revision

web.c Show annotated file Show diff for this revision Revisions of this file
--- a/web.c	Wed Aug 28 07:12:39 2019 +0000
+++ b/web.c	Sun Sep 01 18:12:48 2019 +0000
@@ -52,13 +52,19 @@
 }
 static void handleRequest(int connectionId, int size, char* pRequestStream, uint32_t positionInRequestStream)
 {
-    struct WebConnection* pConnection = NULL;
-    if (!positionInRequestStream) pConnection = WebConnectionNew(connectionId);
-    else                          pConnection = WebConnectionOrNull(connectionId);
-    if (!pConnection)
+    struct WebConnection* pConnection;
+    if (!positionInRequestStream)
+    {
+        pConnection = WebConnectionNew(connectionId);
+    }
+    else
     {
-        LogTimeF("WebRequest - no connection corresponds to id %d\r\n", connectionId);
-        return;
+        pConnection = WebConnectionOrNull(connectionId);
+        if (!pConnection)
+        {
+            LogTimeF("WebRequest - no connection corresponds to id %d\r\n", connectionId);
+            return;
+        }
     }
     
     pConnection->delayUntil = MsTimerCount; //Default to no delay unless modified;
@@ -120,7 +126,7 @@
 static bool pollSomethingToSend(int connectionId, bool clientFinished) //returns true if finished; false if not; 
 {
     struct WebConnection* pConnection = WebConnectionOrNull(connectionId);
-    if (!pConnection) return false;
+    if (!pConnection) return false; //Protects the gap between the connection being established and the request being started
     
     if (!pConnection->toDo)
     {