Преглед изворни кода

Apply patch #9472: tcp_kill_prio: Don't kill active connection that has the same priority
in a modified, IMHO more readable way.

Dirk Ziegelmeier пре 8 година
родитељ
комит
d8b6cdffcb
3 измењених фајлова са 20 додато и 3 уклоњено
  1. 4 0
      CHANGELOG
  2. 3 0
      UPGRADING
  3. 13 3
      src/core/tcp.c

+ 4 - 0
CHANGELOG

@@ -6,6 +6,10 @@ HISTORY
 
 
   ++ New features:
   ++ New features:
 
 
+  2017-11-06: Axel Lin
+  * TCP: kill existing connections with a LOWER priority than the one currently being opened.
+    Previous implementations also kill existing connections of the SAME priority.
+
   2017-09-21: Kalle Olavi Niemitalo
   2017-09-21: Kalle Olavi Niemitalo
   * sockets: add poll() implementation (patch #9450)
   * sockets: add poll() implementation (patch #9450)
 
 

+ 3 - 0
UPGRADING

@@ -10,6 +10,9 @@ with newer versions.
 
 
   ++ Application changes:
   ++ Application changes:
 
 
+  * TCP only kills existing connections with a LOWER priority than the one currently being opened.
+    Previous implementations also kill existing connections of the SAME priority.
+
   * ip4_route_src: parameter order is reversed: ip4_route_src(dest, src) -> ip4_route_src(src, dest)
   * ip4_route_src: parameter order is reversed: ip4_route_src(dest, src) -> ip4_route_src(src, dest)
     to make parameter order consistent with other ip*_route*() functions.
     to make parameter order consistent with other ip*_route*() functions.
     Same also applies to LWIP_HOOK_IP4_ROUTE_SRC() parameter order.
     Same also applies to LWIP_HOOK_IP4_ROUTE_SRC() parameter order.

+ 13 - 3
src/core/tcp.c

@@ -1621,8 +1621,7 @@ tcp_recv_null(void *arg, struct tcp_pcb *pcb, struct pbuf *p, err_t err)
 #endif /* LWIP_CALLBACK_API */
 #endif /* LWIP_CALLBACK_API */
 
 
 /**
 /**
- * Kills the oldest active connection that has the same or lower priority than
- * 'prio'.
+ * Kills the oldest active connection that has a lower priority than 'prio'.
  *
  *
  * @param prio minimum priority
  * @param prio minimum priority
  */
  */
@@ -1635,7 +1634,18 @@ tcp_kill_prio(u8_t prio)
 
 
   mprio = LWIP_MIN(TCP_PRIO_MAX, prio);
   mprio = LWIP_MIN(TCP_PRIO_MAX, prio);
 
 
-  /* We kill the oldest active connection that has the same or lower priority than prio. */
+  /* We want to kill connections with a lower prio, so bail out if 
+   * supplied prio is 0 - there cannot be a no lower prio
+   */
+  if (mprio == 0) {
+    return;
+  }
+
+  /* We want kill connections with a lower prio, so decrement prio by one 
+   * and start searching for oldest connection with same or lower prio than mprio.
+   */
+  mprio--;
+
   inactivity = 0;
   inactivity = 0;
   inactive = NULL;
   inactive = NULL;
   for (pcb = tcp_active_pcbs; pcb != NULL; pcb = pcb->next) {
   for (pcb = tcp_active_pcbs; pcb != NULL; pcb = pcb->next) {