Browse Source

BT6706: rewrite http_server init

balbekova 7 năm trước cách đây
mục cha
commit
c6b11c67e1
1 tập tin đã thay đổi với 20 bổ sung5 xóa
  1. 20 5
      modules/HTTP_Server/http_server.c

+ 20 - 5
modules/HTTP_Server/http_server.c

@@ -442,6 +442,9 @@ static err_t http_accept(void *arg, struct tcp_pcb *pcb, err_t err)
 {
   struct http_state *hs;
 
+  /* set priority for the newly accepted tcp connection newpcb */
+    tcp_setprio(pcb, TCP_PRIO_MIN);
+
   /* Allocate memory for the structure that holds the state of the connection */
   hs = mem_malloc(sizeof(struct http_state));
 
@@ -499,13 +502,25 @@ void HTTP_Init()
 {
 	char buf[MAX_WEB_COOKIE_LEN];
 	uint8_t user_id;
-
+	err_t err;
     struct tcp_pcb *pcb;
 
-    pcb = tcp_new();
-    tcp_bind(pcb, IP_ADDR_ANY, 80);
-    pcb = tcp_listen(pcb);
-    tcp_accept(pcb, http_accept);
+    /*create new pcb*/
+      pcb = tcp_new_ip_type(IPADDR_TYPE_ANY);
+      LWIP_ASSERT("httpd_init: tcp_new failed", pcb != NULL);
+
+      /* set lowest prio to HTTP connections */
+      //tcp_setprio(pcb, TCP_PRIO_MIN);
+
+      /* bind HTTP traffic to pcb */
+      err = tcp_bind(pcb, IP_ANY_TYPE, 80);
+      LWIP_UNUSED_ARG(err); /* in case of LWIP_NOASSERT */
+      LWIP_ASSERT("httpd_init: tcp_bind failed", err == ERR_OK);
+
+      /* start listening on port 80 */
+      pcb = tcp_listen(pcb);
+      /* define callback function for TCP connection setup */
+      tcp_accept(pcb, http_accept);
 
     for (user_id = 0; user_id < MAX_WEB_USERS; user_id++) {
 		/* Flush user cookie by random value */