/[lwip]/lwip/src/core/tcp.c
ViewVC logotype

Diff of /lwip/src/core/tcp.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.25 by likewise, Wed Apr 16 07:39:48 2003 UTC revision 1.26 by likewise, Thu May 1 13:24:01 2003 UTC
# Line 109  void Line 109  void
109  tcp_tmr(void)  tcp_tmr(void)
110  {  {
111    ++tcp_timer;    ++tcp_timer;
112    if(tcp_timer == 10) {    if (tcp_timer == 10) {
113      tcp_timer = 0;      tcp_timer = 0;
114    }    }
115        
116    if(tcp_timer & 1) {    if (tcp_timer & 1) {
117      /* Call tcp_fasttmr() every 200 ms, i.e., every other timer      /* Call tcp_fasttmr() every 200 ms, i.e., every other timer
118         tcp_tmr() is called. */         tcp_tmr() is called. */
119      tcp_fasttmr();      tcp_fasttmr();
120    }    }
121    if(tcp_timer == 0 || tcp_timer == 5) {    if (tcp_timer == 0 || tcp_timer == 5) {
122      /* Call tcp_slowtmr() every 500 ms, i.e., every fifth timer      /* Call tcp_slowtmr() every 500 ms, i.e., every fifth timer
123         tcp_tmr() is called. */         tcp_tmr() is called. */
124      tcp_slowtmr();      tcp_slowtmr();
# Line 142  tcp_close(struct tcp_pcb *pcb) Line 142  tcp_close(struct tcp_pcb *pcb)
142    tcp_debug_print_state(pcb->state);    tcp_debug_print_state(pcb->state);
143    DEBUGF(TCP_DEBUG, ("\n"));    DEBUGF(TCP_DEBUG, ("\n"));
144  #endif /* TCP_DEBUG */  #endif /* TCP_DEBUG */
145    switch(pcb->state) {    switch (pcb->state) {
146    case LISTEN:    case LISTEN:
147      err = ERR_OK;      err = ERR_OK;
148      tcp_pcb_remove((struct tcp_pcb **)&tcp_listen_pcbs, pcb);      tcp_pcb_remove((struct tcp_pcb **)&tcp_listen_pcbs, pcb);
# Line 157  tcp_close(struct tcp_pcb *pcb) Line 157  tcp_close(struct tcp_pcb *pcb)
157      break;      break;
158    case SYN_RCVD:    case SYN_RCVD:
159      err = tcp_send_ctrl(pcb, TCP_FIN);      err = tcp_send_ctrl(pcb, TCP_FIN);
160      if(err == ERR_OK) {      if (err == ERR_OK) {
161        pcb->state = FIN_WAIT_1;        pcb->state = FIN_WAIT_1;
162      }      }
163      break;      break;
164    case ESTABLISHED:    case ESTABLISHED:
165      err = tcp_send_ctrl(pcb, TCP_FIN);      err = tcp_send_ctrl(pcb, TCP_FIN);
166      if(err == ERR_OK) {      if (err == ERR_OK) {
167        pcb->state = FIN_WAIT_1;        pcb->state = FIN_WAIT_1;
168      }      }
169      break;      break;
170    case CLOSE_WAIT:    case CLOSE_WAIT:
171      err = tcp_send_ctrl(pcb, TCP_FIN);      err = tcp_send_ctrl(pcb, TCP_FIN);
172      if(err == ERR_OK) {      if (err == ERR_OK) {
173        pcb->state = LAST_ACK;        pcb->state = LAST_ACK;
174      }      }
175      break;      break;
# Line 180  tcp_close(struct tcp_pcb *pcb) Line 180  tcp_close(struct tcp_pcb *pcb)
180      break;      break;
181    }    }
182    
183    if(pcb != NULL && err == ERR_OK) {    if (pcb != NULL && err == ERR_OK) {
184      err = tcp_output(pcb);      err = tcp_output(pcb);
185    }    }
186    return err;    return err;
# Line 210  tcp_abort(struct tcp_pcb *pcb) Line 210  tcp_abort(struct tcp_pcb *pcb)
210    /* Figure out on which TCP PCB list we are, and remove us. If we    /* Figure out on which TCP PCB list we are, and remove us. If we
211       are in an active state, call the receive function associated with       are in an active state, call the receive function associated with
212       the PCB with a NULL argument, and send an RST to the remote end. */       the PCB with a NULL argument, and send an RST to the remote end. */
213    if(pcb->state == TIME_WAIT) {    if (pcb->state == TIME_WAIT) {
214      tcp_pcb_remove(&tcp_tw_pcbs, pcb);      tcp_pcb_remove(&tcp_tw_pcbs, pcb);
215      memp_free(MEMP_TCP_PCB, pcb);      memp_free(MEMP_TCP_PCB, pcb);
216    } else {    } else {
# Line 225  tcp_abort(struct tcp_pcb *pcb) Line 225  tcp_abort(struct tcp_pcb *pcb)
225  #endif /* LWIP_CALLBACK_API */  #endif /* LWIP_CALLBACK_API */
226      errf_arg = pcb->callback_arg;      errf_arg = pcb->callback_arg;
227      tcp_pcb_remove(&tcp_active_pcbs, pcb);      tcp_pcb_remove(&tcp_active_pcbs, pcb);
228      if(pcb->unacked != NULL) {      if (pcb->unacked != NULL) {
229        tcp_segs_free(pcb->unacked);        tcp_segs_free(pcb->unacked);
230      }      }
231      if(pcb->unsent != NULL) {      if (pcb->unsent != NULL) {
232        tcp_segs_free(pcb->unsent);        tcp_segs_free(pcb->unsent);
233      }      }
234  #if TCP_QUEUE_OOSEQ      #if TCP_QUEUE_OOSEQ    
235      if(pcb->ooseq != NULL) {      if (pcb->ooseq != NULL) {
236        tcp_segs_free(pcb->ooseq);        tcp_segs_free(pcb->ooseq);
237      }      }
238  #endif /* TCP_QUEUE_OOSEQ */  #endif /* TCP_QUEUE_OOSEQ */
# Line 257  tcp_bind(struct tcp_pcb *pcb, struct ip_ Line 257  tcp_bind(struct tcp_pcb *pcb, struct ip_
257  {  {
258    struct tcp_pcb *cpcb;    struct tcp_pcb *cpcb;
259    
260    if(port == 0) {    if (port == 0) {
261      port = tcp_new_port();      port = tcp_new_port();
262    }    }
263    
264    /* Check if the address already is in use. */    /* Check if the address already is in use. */
265    for(cpcb = (struct tcp_pcb *)tcp_listen_pcbs;    for(cpcb = (struct tcp_pcb *)tcp_listen_pcbs;
266        cpcb != NULL; cpcb = cpcb->next) {        cpcb != NULL; cpcb = cpcb->next) {
267      if(cpcb->local_port == port) {      if (cpcb->local_port == port) {
268        if(ip_addr_isany(&(cpcb->local_ip)) ||        if (ip_addr_isany(&(cpcb->local_ip)) ||
269          ip_addr_isany(ipaddr) ||          ip_addr_isany(ipaddr) ||
270          ip_addr_cmp(&(cpcb->local_ip), ipaddr)) {          ip_addr_cmp(&(cpcb->local_ip), ipaddr)) {
271            return ERR_USE;            return ERR_USE;
# Line 274  tcp_bind(struct tcp_pcb *pcb, struct ip_ Line 274  tcp_bind(struct tcp_pcb *pcb, struct ip_
274    }    }
275    for(cpcb = tcp_active_pcbs;    for(cpcb = tcp_active_pcbs;
276        cpcb != NULL; cpcb = cpcb->next) {        cpcb != NULL; cpcb = cpcb->next) {
277      if(cpcb->local_port == port) {      if (cpcb->local_port == port) {
278        if(ip_addr_isany(&(cpcb->local_ip)) ||        if (ip_addr_isany(&(cpcb->local_ip)) ||
279           ip_addr_isany(ipaddr) ||           ip_addr_isany(ipaddr) ||
280           ip_addr_cmp(&(cpcb->local_ip), ipaddr)) {           ip_addr_cmp(&(cpcb->local_ip), ipaddr)) {
281          return ERR_USE;          return ERR_USE;
282        }        }
283      }      }
284    }    }
285    if(!ip_addr_isany(ipaddr)) {    if (!ip_addr_isany(ipaddr)) {
286      pcb->local_ip = *ipaddr;      pcb->local_ip = *ipaddr;
287    }    }
288    pcb->local_port = port;    pcb->local_port = port;
# Line 314  tcp_listen(struct tcp_pcb *pcb) Line 314  tcp_listen(struct tcp_pcb *pcb)
314    struct tcp_pcb_listen *lpcb;    struct tcp_pcb_listen *lpcb;
315    
316    /* already listening? */    /* already listening? */
317    if(pcb->state == LISTEN) {    if (pcb->state == LISTEN) {
318      return pcb;      return pcb;
319    }    }
320    lpcb = memp_malloc(MEMP_TCP_PCB_LISTEN);    lpcb = memp_malloc(MEMP_TCP_PCB_LISTEN);
321    if(lpcb == NULL) {    if (lpcb == NULL) {
322      return NULL;      return NULL;
323    }    }
324    lpcb->callback_arg = pcb->callback_arg;    lpcb->callback_arg = pcb->callback_arg;
# Line 346  void Line 346  void
346  tcp_recved(struct tcp_pcb *pcb, u16_t len)  tcp_recved(struct tcp_pcb *pcb, u16_t len)
347  {  {
348    pcb->rcv_wnd += len;    pcb->rcv_wnd += len;
349    if(pcb->rcv_wnd > TCP_WND) {    if (pcb->rcv_wnd > TCP_WND) {
350      pcb->rcv_wnd = TCP_WND;      pcb->rcv_wnd = TCP_WND;
351    }    }
352    if(!(pcb->flags & TF_ACK_DELAY) &&    if (!(pcb->flags & TF_ACK_DELAY) &&
353       !(pcb->flags & TF_ACK_NOW)) {       !(pcb->flags & TF_ACK_NOW)) {
354      tcp_ack(pcb);      tcp_ack(pcb);
355    }    }
# Line 375  tcp_new_port(void) Line 375  tcp_new_port(void)
375    static u16_t port = TCP_LOCAL_PORT_RANGE_START;    static u16_t port = TCP_LOCAL_PORT_RANGE_START;
376        
377   again:   again:
378    if(++port > TCP_LOCAL_PORT_RANGE_END) {    if (++port > TCP_LOCAL_PORT_RANGE_END) {
379      port = TCP_LOCAL_PORT_RANGE_START;      port = TCP_LOCAL_PORT_RANGE_START;
380    }    }
381        
382    for(pcb = tcp_active_pcbs; pcb != NULL; pcb = pcb->next) {    for(pcb = tcp_active_pcbs; pcb != NULL; pcb = pcb->next) {
383      if(pcb->local_port == port) {      if (pcb->local_port == port) {
384        goto again;        goto again;
385      }      }
386    }    }
387    for(pcb = tcp_tw_pcbs; pcb != NULL; pcb = pcb->next) {    for(pcb = tcp_tw_pcbs; pcb != NULL; pcb = pcb->next) {
388      if(pcb->local_port == port) {      if (pcb->local_port == port) {
389        goto again;        goto again;
390      }      }
391    }    }
392    for(pcb = (struct tcp_pcb *)tcp_listen_pcbs; pcb != NULL; pcb = pcb->next) {    for(pcb = (struct tcp_pcb *)tcp_listen_pcbs; pcb != NULL; pcb = pcb->next) {
393      if(pcb->local_port == port) {      if (pcb->local_port == port) {
394        goto again;        goto again;
395      }      }
396    }    }
# Line 414  tcp_connect(struct tcp_pcb *pcb, struct Line 414  tcp_connect(struct tcp_pcb *pcb, struct
414    u32_t iss;    u32_t iss;
415    
416    DEBUGF(TCP_DEBUG, ("tcp_connect to port %u\n", port));    DEBUGF(TCP_DEBUG, ("tcp_connect to port %u\n", port));
417    if(ipaddr != NULL) {    if (ipaddr != NULL) {
418      pcb->remote_ip = *ipaddr;      pcb->remote_ip = *ipaddr;
419    } else {    } else {
420      return ERR_VAL;      return ERR_VAL;
421    }    }
422    pcb->remote_port = port;    pcb->remote_port = port;
423    if(pcb->local_port == 0) {    if (pcb->local_port == 0) {
424      pcb->local_port = tcp_new_port();      pcb->local_port = tcp_new_port();
425    }    }
426    iss = tcp_next_iss();    iss = tcp_next_iss();
# Line 446  tcp_connect(struct tcp_pcb *pcb, struct Line 446  tcp_connect(struct tcp_pcb *pcb, struct
446                    (pcb->mss & 255));                    (pcb->mss & 255));
447    
448    ret = tcp_enqueue(pcb, NULL, 0, TCP_SYN, 0, (u8_t *)&optdata, 4);    ret = tcp_enqueue(pcb, NULL, 0, TCP_SYN, 0, (u8_t *)&optdata, 4);
449    if(ret == ERR_OK) {    if (ret == ERR_OK) {
450      tcp_output(pcb);      tcp_output(pcb);
451    }    }
452    return ret;    return ret;
# Line 508  tcp_slowtmr(void) Line 508  tcp_slowtmr(void)
508          /* Reduce congestion window and ssthresh. */          /* Reduce congestion window and ssthresh. */
509          eff_wnd = MIN(pcb->cwnd, pcb->snd_wnd);          eff_wnd = MIN(pcb->cwnd, pcb->snd_wnd);
510          pcb->ssthresh = eff_wnd >> 1;          pcb->ssthresh = eff_wnd >> 1;
511          if(pcb->ssthresh < pcb->mss) {          if (pcb->ssthresh < pcb->mss) {
512            pcb->ssthresh = pcb->mss * 2;            pcb->ssthresh = pcb->mss * 2;
513          }          }
514          pcb->cwnd = pcb->mss;          pcb->cwnd = pcb->mss;
# Line 518  tcp_slowtmr(void) Line 518  tcp_slowtmr(void)
518      }      }
519      /* Check if this PCB has stayed too long in FIN-WAIT-2 */      /* Check if this PCB has stayed too long in FIN-WAIT-2 */
520      if (pcb->state == FIN_WAIT_2) {      if (pcb->state == FIN_WAIT_2) {
521        if((u32_t)(tcp_ticks - pcb->tmr) >        if ((u32_t)(tcp_ticks - pcb->tmr) >
522          TCP_FIN_WAIT_TIMEOUT / TCP_SLOW_INTERVAL) {          TCP_FIN_WAIT_TIMEOUT / TCP_SLOW_INTERVAL) {
523          ++pcb_remove;          ++pcb_remove;
524          DEBUGF(TCP_DEBUG, ("tcp_slowtmr: removing pcb stuck in FIN-WAIT-2\n"));          DEBUGF(TCP_DEBUG, ("tcp_slowtmr: removing pcb stuck in FIN-WAIT-2\n"));
# Line 529  tcp_slowtmr(void) Line 529  tcp_slowtmr(void)
529         inactive for too long, will drop the data (it will eventually         inactive for too long, will drop the data (it will eventually
530         be retransmitted). */         be retransmitted). */
531  #if TCP_QUEUE_OOSEQ      #if TCP_QUEUE_OOSEQ    
532      if(pcb->ooseq != NULL &&      if (pcb->ooseq != NULL &&
533         (u32_t)tcp_ticks - pcb->tmr >=         (u32_t)tcp_ticks - pcb->tmr >=
534         pcb->rto * TCP_OOSEQ_TIMEOUT) {         pcb->rto * TCP_OOSEQ_TIMEOUT) {
535        tcp_segs_free(pcb->ooseq);        tcp_segs_free(pcb->ooseq);
# Line 539  tcp_slowtmr(void) Line 539  tcp_slowtmr(void)
539  #endif /* TCP_QUEUE_OOSEQ */  #endif /* TCP_QUEUE_OOSEQ */
540    
541      /* Check if this PCB has stayed too long in SYN-RCVD */      /* Check if this PCB has stayed too long in SYN-RCVD */
542      if(pcb->state == SYN_RCVD) {      if (pcb->state == SYN_RCVD) {
543        if((u32_t)(tcp_ticks - pcb->tmr) >        if ((u32_t)(tcp_ticks - pcb->tmr) >
544           TCP_SYN_RCVD_TIMEOUT / TCP_SLOW_INTERVAL) {           TCP_SYN_RCVD_TIMEOUT / TCP_SLOW_INTERVAL) {
545          ++pcb_remove;          ++pcb_remove;
546          DEBUGF(TCP_DEBUG, ("tcp_slowtmr: removing pcb stuck in SYN-RCVD\n"));          DEBUGF(TCP_DEBUG, ("tcp_slowtmr: removing pcb stuck in SYN-RCVD\n"));
# Line 549  tcp_slowtmr(void) Line 549  tcp_slowtmr(void)
549    
550    
551      /* If the PCB should be removed, do it. */      /* If the PCB should be removed, do it. */
552      if(pcb_remove) {      if (pcb_remove) {
553        tcp_pcb_purge(pcb);              tcp_pcb_purge(pcb);      
554        /* Remove PCB from tcp_active_pcbs list. */        /* Remove PCB from tcp_active_pcbs list. */
555        if(prev != NULL) {        if (prev != NULL) {
556          LWIP_ASSERT("tcp_slowtmr: middle tcp != tcp_active_pcbs", pcb != tcp_active_pcbs);          LWIP_ASSERT("tcp_slowtmr: middle tcp != tcp_active_pcbs", pcb != tcp_active_pcbs);
557          prev->next = pcb->next;          prev->next = pcb->next;
558        } else {        } else {
# Line 570  tcp_slowtmr(void) Line 570  tcp_slowtmr(void)
570    
571        /* We check if we should poll the connection. */        /* We check if we should poll the connection. */
572        ++pcb->polltmr;        ++pcb->polltmr;
573        if(pcb->polltmr >= pcb->pollinterval) {        if (pcb->polltmr >= pcb->pollinterval) {
574          pcb->polltmr = 0;          pcb->polltmr = 0;
575          DEBUGF(TCP_DEBUG, ("tcp_slowtmr: polling application\n"));          DEBUGF(TCP_DEBUG, ("tcp_slowtmr: polling application\n"));
576          TCP_EVENT_POLL(pcb, err);          TCP_EVENT_POLL(pcb, err);
577          if(err == ERR_OK) {          if (err == ERR_OK) {
578            tcp_output(pcb);            tcp_output(pcb);
579          }          }
580        }        }
# Line 588  tcp_slowtmr(void) Line 588  tcp_slowtmr(void)
588    /* Steps through all of the TIME-WAIT PCBs. */    /* Steps through all of the TIME-WAIT PCBs. */
589    prev = NULL;        prev = NULL;    
590    pcb = tcp_tw_pcbs;    pcb = tcp_tw_pcbs;
591    while(pcb != NULL) {    while (pcb != NULL) {
592      LWIP_ASSERT("tcp_slowtmr: TIME-WAIT pcb->state == TIME-WAIT", pcb->state == TIME_WAIT);      LWIP_ASSERT("tcp_slowtmr: TIME-WAIT pcb->state == TIME-WAIT", pcb->state == TIME_WAIT);
593      pcb_remove = 0;      pcb_remove = 0;
594    
595      /* Check if this PCB has stayed long enough in TIME-WAIT */      /* Check if this PCB has stayed long enough in TIME-WAIT */
596      if((u32_t)(tcp_ticks - pcb->tmr) > 2 * TCP_MSL / TCP_SLOW_INTERVAL) {      if ((u32_t)(tcp_ticks - pcb->tmr) > 2 * TCP_MSL / TCP_SLOW_INTERVAL) {
597        ++pcb_remove;        ++pcb_remove;
598      }      }
599            
600    
601    
602      /* If the PCB should be removed, do it. */      /* If the PCB should be removed, do it. */
603      if(pcb_remove) {      if (pcb_remove) {
604        tcp_pcb_purge(pcb);              tcp_pcb_purge(pcb);      
605        /* Remove PCB from tcp_tw_pcbs list. */        /* Remove PCB from tcp_tw_pcbs list. */
606        if(prev != NULL) {        if (prev != NULL) {
607          LWIP_ASSERT("tcp_slowtmr: middle tcp != tcp_tw_pcbs", pcb != tcp_tw_pcbs);          LWIP_ASSERT("tcp_slowtmr: middle tcp != tcp_tw_pcbs", pcb != tcp_tw_pcbs);
608          prev->next = pcb->next;          prev->next = pcb->next;
609        } else {        } else {
# Line 634  tcp_fasttmr(void) Line 634  tcp_fasttmr(void)
634    
635    /* send delayed ACKs */      /* send delayed ACKs */  
636    for(pcb = tcp_active_pcbs; pcb != NULL; pcb = pcb->next) {    for(pcb = tcp_active_pcbs; pcb != NULL; pcb = pcb->next) {
637      if(pcb->flags & TF_ACK_DELAY) {      if (pcb->flags & TF_ACK_DELAY) {
638        DEBUGF(TCP_DEBUG, ("tcp_fasttmr: delayed ACK\n"));        DEBUGF(TCP_DEBUG, ("tcp_fasttmr: delayed ACK\n"));
639        tcp_ack_now(pcb);        tcp_ack_now(pcb);
640        pcb->flags &= ~(TF_ACK_DELAY | TF_ACK_NOW);        pcb->flags &= ~(TF_ACK_DELAY | TF_ACK_NOW);
# Line 655  tcp_segs_free(struct tcp_seg *seg) Line 655  tcp_segs_free(struct tcp_seg *seg)
655    u8_t count = 0;    u8_t count = 0;
656    struct tcp_seg *next;    struct tcp_seg *next;
657   again:     again:  
658    if(seg != NULL) {    if (seg != NULL) {
659      next = seg->next;      next = seg->next;
660      count += tcp_seg_free(seg);      count += tcp_seg_free(seg);
661      seg = next;      seg = next;
# Line 676  tcp_seg_free(struct tcp_seg *seg) Line 676  tcp_seg_free(struct tcp_seg *seg)
676  {  {
677    u8_t count = 0;    u8_t count = 0;
678        
679    if(seg != NULL) {    if (seg != NULL) {
680      if(seg->p == NULL) {      if (seg->p == NULL) {
681        memp_free(MEMP_TCP_SEG, seg);        memp_free(MEMP_TCP_SEG, seg);
682      } else {      } else {
683        count = pbuf_free(seg->p);        count = pbuf_free(seg->p);
# Line 716  tcp_seg_copy(struct tcp_seg *seg) Line 716  tcp_seg_copy(struct tcp_seg *seg)
716    struct tcp_seg *cseg;    struct tcp_seg *cseg;
717    
718    cseg = memp_malloc(MEMP_TCP_SEG);    cseg = memp_malloc(MEMP_TCP_SEG);
719    if(cseg == NULL) {    if (cseg == NULL) {
720      return NULL;      return NULL;
721    }    }
722    memcpy((char *)cseg, (const char *)seg, sizeof(struct tcp_seg));    memcpy((char *)cseg, (const char *)seg, sizeof(struct tcp_seg));
# Line 729  static err_t Line 729  static err_t
729  tcp_recv_null(void *arg, struct tcp_pcb *pcb, struct pbuf *p, err_t err)  tcp_recv_null(void *arg, struct tcp_pcb *pcb, struct pbuf *p, err_t err)
730  {  {
731    arg = arg;    arg = arg;
732    if(p != NULL) {    if (p != NULL) {
733      pbuf_free(p);      pbuf_free(p);
734    } else if(err == ERR_OK) {    } else if (err == ERR_OK) {
735      return tcp_close(pcb);      return tcp_close(pcb);
736    }    }
737    return ERR_OK;    return ERR_OK;
# Line 753  tcp_kill_prio(u8_t prio) Line 753  tcp_kill_prio(u8_t prio)
753    inactivity = 0;    inactivity = 0;
754    inactive = NULL;    inactive = NULL;
755    for(pcb = tcp_active_pcbs; pcb != NULL; pcb = pcb->next) {    for(pcb = tcp_active_pcbs; pcb != NULL; pcb = pcb->next) {
756      if(pcb->prio <= prio &&      if (pcb->prio <= prio &&
757         pcb->prio <= mprio &&         pcb->prio <= mprio &&
758         (u32_t)(tcp_ticks - pcb->tmr) >= inactivity) {         (u32_t)(tcp_ticks - pcb->tmr) >= inactivity) {
759        inactivity = tcp_ticks - pcb->tmr;        inactivity = tcp_ticks - pcb->tmr;
# Line 761  tcp_kill_prio(u8_t prio) Line 761  tcp_kill_prio(u8_t prio)
761        mprio = pcb->prio;        mprio = pcb->prio;
762      }      }
763    }    }
764    if(inactive != NULL) {    if (inactive != NULL) {
765      DEBUGF(TCP_DEBUG, ("tcp_kill_prio: killing oldest PCB 0x%p (%ld)\n",      DEBUGF(TCP_DEBUG, ("tcp_kill_prio: killing oldest PCB 0x%p (%ld)\n",
766                         (void *)inactive, inactivity));                         (void *)inactive, inactivity));
767      tcp_abort(inactive);      tcp_abort(inactive);
# Line 778  tcp_kill_timewait(void) Line 778  tcp_kill_timewait(void)
778    inactivity = 0;    inactivity = 0;
779    inactive = NULL;    inactive = NULL;
780    for(pcb = tcp_tw_pcbs; pcb != NULL; pcb = pcb->next) {    for(pcb = tcp_tw_pcbs; pcb != NULL; pcb = pcb->next) {
781      if((u32_t)(tcp_ticks - pcb->tmr) >= inactivity) {      if ((u32_t)(tcp_ticks - pcb->tmr) >= inactivity) {
782        inactivity = tcp_ticks - pcb->tmr;        inactivity = tcp_ticks - pcb->tmr;
783        inactive = pcb;        inactive = pcb;
784      }      }
785    }    }
786    if(inactive != NULL) {    if (inactive != NULL) {
787      DEBUGF(TCP_DEBUG, ("tcp_kill_timewait: killing oldest TIME-WAIT PCB 0x%p (%ld)\n",      DEBUGF(TCP_DEBUG, ("tcp_kill_timewait: killing oldest TIME-WAIT PCB 0x%p (%ld)\n",
788                         (void *)inactive, inactivity));                         (void *)inactive, inactivity));
789      tcp_abort(inactive);      tcp_abort(inactive);
# Line 799  tcp_alloc(u8_t prio) Line 799  tcp_alloc(u8_t prio)
799    u32_t iss;    u32_t iss;
800        
801    pcb = memp_malloc(MEMP_TCP_PCB);    pcb = memp_malloc(MEMP_TCP_PCB);
802    if(pcb == NULL) {    if (pcb == NULL) {
803      /* Try killing oldest connection in TIME-WAIT. */      /* Try killing oldest connection in TIME-WAIT. */
804      DEBUGF(TCP_DEBUG, ("tcp_alloc: killing off oldest TIME-WAIT connection\n"));      DEBUGF(TCP_DEBUG, ("tcp_alloc: killing off oldest TIME-WAIT connection\n"));
805      tcp_kill_timewait();      tcp_kill_timewait();
806      pcb = memp_malloc(MEMP_TCP_PCB);      pcb = memp_malloc(MEMP_TCP_PCB);
807      if(pcb == NULL) {      if (pcb == NULL) {
808        tcp_kill_prio(prio);            tcp_kill_prio(prio);    
809        pcb = memp_malloc(MEMP_TCP_PCB);        pcb = memp_malloc(MEMP_TCP_PCB);
810      }      }
811    }    }
812    if(pcb != NULL) {    if (pcb != NULL) {
813      memset(pcb, 0, sizeof(struct tcp_pcb));      memset(pcb, 0, sizeof(struct tcp_pcb));
814      pcb->prio = TCP_PRIO_NORMAL;      pcb->prio = TCP_PRIO_NORMAL;
815      pcb->snd_buf = TCP_SND_BUF;      pcb->snd_buf = TCP_SND_BUF;
# Line 963  tcp_accept(struct tcp_pcb *pcb, Line 963  tcp_accept(struct tcp_pcb *pcb,
963  void  void
964  tcp_pcb_purge(struct tcp_pcb *pcb)  tcp_pcb_purge(struct tcp_pcb *pcb)
965  {  {
966    if(pcb->state != CLOSED &&    if (pcb->state != CLOSED &&
967       pcb->state != TIME_WAIT &&       pcb->state != TIME_WAIT &&
968       pcb->state != LISTEN) {       pcb->state != LISTEN) {
969    
970      DEBUGF(TCP_DEBUG, ("tcp_pcb_purge\n"));      DEBUGF(TCP_DEBUG, ("tcp_pcb_purge\n"));
971            
972  #if TCP_DEBUG  #if TCP_DEBUG
973      if(pcb->unsent != NULL) {          if (pcb->unsent != NULL) {    
974        DEBUGF(TCP_DEBUG, ("tcp_pcb_purge: not all data sent\n"));        DEBUGF(TCP_DEBUG, ("tcp_pcb_purge: not all data sent\n"));
975      }      }
976      if(pcb->unacked != NULL) {          if (pcb->unacked != NULL) {    
977        DEBUGF(TCP_DEBUG, ("tcp_pcb_purge: data left on ->unacked\n"));        DEBUGF(TCP_DEBUG, ("tcp_pcb_purge: data left on ->unacked\n"));
978      }      }
979  #if TCP_QUEUE_OOSEQ /* LW */  #if TCP_QUEUE_OOSEQ /* LW */
980      if(pcb->ooseq != NULL) {          if (pcb->ooseq != NULL) {    
981        DEBUGF(TCP_DEBUG, ("tcp_pcb_purge: data left on ->ooseq\n"));        DEBUGF(TCP_DEBUG, ("tcp_pcb_purge: data left on ->ooseq\n"));
982      }      }
983  #endif  #endif
# Line 1010  tcp_pcb_remove(struct tcp_pcb **pcblist, Line 1010  tcp_pcb_remove(struct tcp_pcb **pcblist,
1010    tcp_pcb_purge(pcb);    tcp_pcb_purge(pcb);
1011        
1012    /* if there is an outstanding delayed ACKs, send it */    /* if there is an outstanding delayed ACKs, send it */
1013    if(pcb->state != TIME_WAIT &&    if (pcb->state != TIME_WAIT &&
1014       pcb->state != LISTEN &&       pcb->state != LISTEN &&
1015       pcb->flags & TF_ACK_DELAY) {       pcb->flags & TF_ACK_DELAY) {
1016      pcb->flags |= TF_ACK_NOW;      pcb->flags |= TF_ACK_NOW;
# Line 1073  void Line 1073  void
1073  tcp_debug_print_state(enum tcp_state s)  tcp_debug_print_state(enum tcp_state s)
1074  {  {
1075    DEBUGF(TCP_DEBUG, ("State: "));    DEBUGF(TCP_DEBUG, ("State: "));
1076    switch(s) {    switch (s) {
1077    case CLOSED:    case CLOSED:
1078      DEBUGF(TCP_DEBUG, ("CLOSED\n"));      DEBUGF(TCP_DEBUG, ("CLOSED\n"));
1079      break;      break;
# Line 1113  tcp_debug_print_state(enum tcp_state s) Line 1113  tcp_debug_print_state(enum tcp_state s)
1113  void  void
1114  tcp_debug_print_flags(u8_t flags)  tcp_debug_print_flags(u8_t flags)
1115  {  {
1116    if(flags & TCP_FIN) {    if (flags & TCP_FIN) {
1117      DEBUGF(TCP_DEBUG, ("FIN "));      DEBUGF(TCP_DEBUG, ("FIN "));
1118    }    }
1119    if(flags & TCP_SYN) {    if (flags & TCP_SYN) {
1120      DEBUGF(TCP_DEBUG, ("SYN "));      DEBUGF(TCP_DEBUG, ("SYN "));
1121    }    }
1122    if(flags & TCP_RST) {    if (flags & TCP_RST) {
1123      DEBUGF(TCP_DEBUG, ("RST "));      DEBUGF(TCP_DEBUG, ("RST "));
1124    }    }
1125    if(flags & TCP_PSH) {    if (flags & TCP_PSH) {
1126      DEBUGF(TCP_DEBUG, ("PSH "));      DEBUGF(TCP_DEBUG, ("PSH "));
1127    }    }
1128    if(flags & TCP_ACK) {    if (flags & TCP_ACK) {
1129      DEBUGF(TCP_DEBUG, ("ACK "));      DEBUGF(TCP_DEBUG, ("ACK "));
1130    }    }
1131    if(flags & TCP_URG) {    if (flags & TCP_URG) {
1132      DEBUGF(TCP_DEBUG, ("URG "));      DEBUGF(TCP_DEBUG, ("URG "));
1133    }    }
1134  }  }

Legend:
Removed from v.1.25  
changed lines
  Added in v.1.26

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26