Neaten Webserver project code.
[pub/USBasp.git] / Projects / Incomplete / Webserver / Lib / WebserverApp.c
index 11acec4..6ac94d6 100644 (file)
@@ -51,7 +51,6 @@ char PROGMEM HTTP404Header[] = "HTTP/1.1 404 Not Found\r\n"
                                "Server: LUFA RNDIS\r\n"\r
                                "Connection: close\r\n\r\n";\r
 \r
                                "Server: LUFA RNDIS\r\n"\r
                                "Connection: close\r\n\r\n";\r
 \r
-/****************************************************************************************/\r
 /** HTTP page to serve to the host when a HTTP request is made. This page is too long for a single response, thus it is automatically\r
  *  broken up into smaller blocks and sent as a series of packets each time the webserver application callback is run.\r
  */\r
 /** HTTP page to serve to the host when a HTTP request is made. This page is too long for a single response, thus it is automatically\r
  *  broken up into smaller blocks and sent as a series of packets each time the webserver application callback is run.\r
  */\r
@@ -75,7 +74,17 @@ char PROGMEM HTTPPage[]   =
                "       </body>"\r
                "</html>";\r
 \r
                "       </body>"\r
                "</html>";\r
 \r
-void WebserverAppCallback(void)\r
+/** Initialization function for the simple HTTP webserver. */\r
+void WebserverApp_Init(void)\r
+{\r
+       /* Listen on port 80 for HTTP connections from hosts */\r
+       uip_listen(HTONS(80));\r
+}\r
+\r
+/** uIP stack application callback for the simple HTTP webserver. This function must be called each time the\r
+ *  TCP/IP stack needs a TCP packet to be processed.\r
+ */\r
+void WebserverApp_Callback(void)\r
 {\r
        char*    AppDataPtr  = (char*)uip_appdata;\r
        uint16_t AppDataSize = 0;\r
 {\r
        char*    AppDataPtr  = (char*)uip_appdata;\r
        uint16_t AppDataSize = 0;\r
@@ -116,10 +125,12 @@ void WebserverAppCallback(void)
        }\r
        else if (BytesRemaining > MaxSegSize)\r
        {\r
        }\r
        else if (BytesRemaining > MaxSegSize)\r
        {\r
+               /* More bytes remaining to send than the maximum segment size, send next chunk */\r
                AppDataSize = MaxSegSize;\r
        }\r
        else\r
        {\r
                AppDataSize = MaxSegSize;\r
        }\r
        else\r
        {\r
+               /* Less bytes than the segment size remaining, send all remaining bytes in the one packet */\r
                AppDataSize = BytesRemaining;\r
        }\r
 \r
                AppDataSize = BytesRemaining;\r
        }\r
 \r