Commit for the 100219 release.
[pub/USBasp.git] / Projects / Webserver / Lib / HTTPServerApp.c
index b6277d3..4e00952 100644 (file)
@@ -100,13 +100,9 @@ void HTTPServerApp_Callback(void)
 \r
        if (uip_aborted() || uip_timedout() || uip_closed())\r
        {\r
-               /* Connection is being terminated for some reason - close file handle */\r
-               f_close(&AppState->HTTPServer.FileHandle);\r
-               AppState->HTTPServer.FileOpen = false;\r
-               \r
                /* Lock to the closed state so that no further processing will occur on the connection */\r
-               AppState->HTTPServer.CurrentState  = WEBSERVER_STATE_Closed;\r
-               AppState->HTTPServer.NextState     = WEBSERVER_STATE_Closed;\r
+               AppState->HTTPServer.CurrentState  = WEBSERVER_STATE_Closing;\r
+               AppState->HTTPServer.NextState     = WEBSERVER_STATE_Closing;\r
        }\r
 \r
        if (uip_connected())\r
@@ -148,9 +144,15 @@ void HTTPServerApp_Callback(void)
                                HTTPServerApp_SendData();\r
                                break;\r
                        case WEBSERVER_STATE_Closing:\r
+                               /* Connection is being terminated for some reason - close file handle */\r
+                               f_close(&AppState->HTTPServer.FileHandle);\r
+                               AppState->HTTPServer.FileOpen = false;\r
+               \r
+                               /* If connection is not already closed, close it */\r
                                uip_close();\r
                                \r
-                               AppState->HTTPServer.NextState = WEBSERVER_STATE_Closed;\r
+                               AppState->HTTPServer.CurrentState = WEBSERVER_STATE_Closed;\r
+                               AppState->HTTPServer.NextState    = WEBSERVER_STATE_Closed;\r
                                break;\r
                }                 \r
        }               \r