Better HTTP GET parsing in the Webserver demo, add application polling.
[pub/USBasp.git] / Projects / Webserver / Lib / uIPManagement.c
index f001193..c816dea 100644 (file)
@@ -52,7 +52,7 @@ void uIPManagement_Init(void)
 {\r
        /* uIP Timing Initialization */\r
        clock_init();\r
-       timer_set(&ConnectionTimer, CLOCK_SECOND / 100);\r
+       timer_set(&ConnectionTimer, CLOCK_SECOND / 2);\r
        timer_set(&ARPTimer, CLOCK_SECOND * 10);        \r
 \r
        /* uIP Stack Initialization */\r
@@ -97,13 +97,13 @@ static void uIPManagement_ProcessIncommingPacket(void)
                LEDs_SetAllLEDs(LEDMASK_USB_BUSY);\r
 \r
                /* Read the incomming packet straight into the UIP packet buffer */\r
-               RNDIS_Host_ReadPacket(&Ethernet_RNDIS_Interface, &uip_buf[0], &uip_len);\r
+               RNDIS_Host_ReadPacket(&Ethernet_RNDIS_Interface, uip_buf, &uip_len);\r
 \r
                if (uip_len > 0)\r
                {\r
                        bool PacketHandled = true;\r
 \r
-                       struct uip_eth_hdr* EthernetHeader = (struct uip_eth_hdr*)&uip_buf[0];\r
+                       struct uip_eth_hdr* EthernetHeader = (struct uip_eth_hdr*)uip_buf;\r
                        if (EthernetHeader->type == HTONS(UIP_ETHTYPE_IP))\r
                        {\r
                                /* Filter packet by MAC destination */\r
@@ -128,7 +128,7 @@ static void uIPManagement_ProcessIncommingPacket(void)
 \r
                        /* If a response was generated, send it */\r
                        if ((uip_len > 0) && PacketHandled)\r
-                         RNDIS_Host_SendPacket(&Ethernet_RNDIS_Interface, &uip_buf[0], uip_len);\r
+                         RNDIS_Host_SendPacket(&Ethernet_RNDIS_Interface, uip_buf, uip_len);\r
                }\r
 \r
                LEDs_SetAllLEDs(LEDMASK_USB_READY);\r
@@ -138,7 +138,22 @@ static void uIPManagement_ProcessIncommingPacket(void)
 /** Manages the currently open network connections, including TCP and (if enabled) UDP. */\r
 static void uIPManagement_ManageConnections(void)\r
 {\r
-       /* Manage open connections */\r
+       /* Poll TCP connections for more data to send back to the host */\r
+       for (uint8_t i = 0; i < UIP_CONNS; i++)\r
+       {\r
+               uip_poll_conn(&uip_conns[i]);\r
+\r
+               /* If a response was generated, send it */\r
+               if (uip_len > 0)\r
+               {\r
+                       /* Add destination MAC to outgoing packet */\r
+                       uip_arp_out();\r
+\r
+                       RNDIS_Host_SendPacket(&Ethernet_RNDIS_Interface, uip_buf, uip_len);\r
+               }\r
+       }\r
+\r
+       /* Manage open connections for timeouts */\r
        if (timer_expired(&ConnectionTimer))\r
        {\r
                timer_reset(&ConnectionTimer);\r
@@ -156,7 +171,7 @@ static void uIPManagement_ManageConnections(void)
                                /* Add destination MAC to outgoing packet */\r
                                uip_arp_out();\r
 \r
-                               RNDIS_Host_SendPacket(&Ethernet_RNDIS_Interface, &uip_buf[0], uip_len);\r
+                               RNDIS_Host_SendPacket(&Ethernet_RNDIS_Interface, uip_buf, uip_len);\r
                        }\r
                }\r
                \r
@@ -172,7 +187,7 @@ static void uIPManagement_ManageConnections(void)
                                /* Add destination MAC to outgoing packet */\r
                                uip_arp_out();\r
 \r
-                               RNDIS_Host_SendPacket(&Ethernet_RNDIS_Interface, &uip_buf[0], uip_len);\r
+                               RNDIS_Host_SendPacket(&Ethernet_RNDIS_Interface, uip_buf, uip_len);\r
                        }\r
                }\r
                #endif\r