11/*
22 * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
3- * All rights reserved.
4- *
5- * Redistribution and use in source and binary forms, with or without modification,
3+ * All rights reserved.
4+ *
5+ * Redistribution and use in source and binary forms, with or without modification,
66 * are permitted provided that the following conditions are met:
77 *
88 * 1. Redistributions of source code must retain the above copyright notice,
1111 * this list of conditions and the following disclaimer in the documentation
1212 * and/or other materials provided with the distribution.
1313 * 3. The name of the author may not be used to endorse or promote products
14- * derived from this software without specific prior written permission.
14+ * derived from this software without specific prior written permission.
1515 *
16- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
17- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18- * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
19- * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
20- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
21- * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
24- * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
16+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
17+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
19+ * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
20+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
21+ * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
24+ * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
2525 * OF SUCH DAMAGE.
2626 *
2727 * This file is part of the lwIP TCP/IP stack.
28- *
28+ *
2929 * Author: Adam Dunkels <[email protected] > 3030 *
3131 */
@@ -284,7 +284,7 @@ struct tcp_seg {
284284 u16_t oversize_left ; /* Extra bytes available at the end of the last
285285 pbuf in unsent (used for asserting vs.
286286 tcp_pcb.unsent_oversized only) */
287- #endif /* TCP_OVERSIZE_DBGCHECK */
287+ #endif /* TCP_OVERSIZE_DBGCHECK */
288288#if TCP_CHECKSUM_ON_COPY
289289 u16_t chksum ;
290290 u8_t chksum_swapped ;
@@ -313,7 +313,7 @@ extern u32_t tcp_ticks;
313313
314314/* The TCP PCB lists. */
315315union tcp_listen_pcbs_t { /* List of all TCP PCBs in LISTEN state. */
316- struct tcp_pcb_listen * listen_pcbs ;
316+ struct tcp_pcb_listen * listen_pcbs ;
317317 struct tcp_pcb * pcbs ;
318318};
319319extern struct tcp_pcb * tcp_bound_pcbs ;
@@ -325,7 +325,7 @@ extern struct tcp_pcb *tcp_tw_pcbs; /* List of all TCP PCBs in TIME-WAIT. *
325325
326326extern struct tcp_pcb * tcp_tmp_pcb ; /* Only used for temporary storage. */
327327
328- /* Axioms about the above lists:
328+ /* Axioms about the above lists:
329329 1) Every TCP PCB that is not CLOSED is in one of the lists.
330330 2) A PCB is only in one of the lists.
331331 3) All PCBs in the tcp_listen_pcbs list is in LISTEN state.
@@ -396,6 +396,26 @@ extern struct tcp_pcb *tcp_tmp_pcb; /* Only used for temporary storage. */
396396
397397#endif /* LWIP_DEBUG */
398398
399+ #define TCP_TW_LIMIT (l ) \
400+ do { \
401+ u32_t tcp_tmp_pcbs_count = 0; \
402+ tcp_tmp_pcb = tcp_tw_pcbs; \
403+ while(tcp_tmp_pcb != NULL) { \
404+ if(++tcp_tmp_pcbs_count == (l)) { \
405+ struct tcp_pcb *_tcp_tmp_pcb = tcp_tmp_pcb->next; \
406+ tcp_tmp_pcb->next = NULL; \
407+ tcp_tmp_pcb = _tcp_tmp_pcb; \
408+ while(tcp_tmp_pcb != NULL) { \
409+ _tcp_tmp_pcb = tcp_tmp_pcb; \
410+ tcp_pcb_purge(tcp_tmp_pcb); \
411+ tcp_tmp_pcb = tcp_tmp_pcb->next; \
412+ memp_free(MEMP_TCP_PCB, _tcp_tmp_pcb); \
413+ } \
414+ break; \
415+ } \
416+ tcp_tmp_pcb = tcp_tmp_pcb->next; \
417+ } \
418+ } while(0)
399419
400420/* Internal functions: */
401421struct tcp_pcb * tcp_pcb_copy (struct tcp_pcb * pcb )ICACHE_FLASH_ATTR ;
0 commit comments