This is an example code in the official document to learn how UIP processes Web servers.
Struct example5_state {char * dataptr; unsigned int dataleft;} void example5_init (void) {uip_listen (htons (80); values (htons (81);} void example5_app (void) {struct example5_state * s; S = (struct example5_state) uip_conn-> appstate; If (uip_connected () {Switch (uip_conn-> lport) {Case htons (80 ): s-> dataptr = data_port_80; s-> dataleft = datalen_port_80; break; Case htons (81): S-> dataptr = data_port_81; s-> dataleft = break ;} uip_send (S-> dataptr, S-> dataleft); return;} If (uip_acked () {If (S-> dateleft <uip_mss () {uip_close (); return;} s-> dataptr + = uip_conn-> Len; s-> dataleft-= uip_conn-> Len; uip_send (S-> dataptr, S-> dataleft );}
The struct contains the address and length of the file to be sent. The initialization function listens to ports 80 and 81 respectively. The app function processes different connections based on the port value. This app responds to the drive uip_asked (). If the length of the file to be sent is smaller than the length returned by uip_mss (), it means that the file has been sent and uip_close () is executed (). If no, adjust the file pointer and length information and continue sending through uip_send.