/[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.28 by jani, Tue May 27 13:44:08 2003 UTC revision 1.29 by likewise, Mon Jun 9 21:14:47 2003 UTC
# Line 64  const u8_t tcp_backoff[13] = Line 64  const u8_t tcp_backoff[13] =
64  /* The TCP PCB lists. */  /* The TCP PCB lists. */
65  struct tcp_pcb_listen *tcp_listen_pcbs;  /* List of all TCP PCBs in LISTEN state. */  struct tcp_pcb_listen *tcp_listen_pcbs;  /* List of all TCP PCBs in LISTEN state. */
66  struct tcp_pcb *tcp_active_pcbs;  /* List of all TCP PCBs that are in a  struct tcp_pcb *tcp_active_pcbs;  /* List of all TCP PCBs that are in a
67                                   state in which they accept or send           state in which they accept or send
68                                   data. */           data. */
69  struct tcp_pcb *tcp_tw_pcbs;      /* List of all TCP PCBs in TIME-WAIT. */  struct tcp_pcb *tcp_tw_pcbs;      /* List of all TCP PCBs in TIME-WAIT. */
70    
71  struct tcp_pcb *tcp_tmp_pcb;  struct tcp_pcb *tcp_tmp_pcb;
# Line 274  tcp_bind(struct tcp_pcb *pcb, struct ip_ Line 274  tcp_bind(struct tcp_pcb *pcb, struct ip_
274        cpcb != NULL; cpcb = cpcb->next) {        cpcb != NULL; cpcb = cpcb->next) {
275      if (cpcb->local_port == port) {      if (cpcb->local_port == port) {
276        if (ip_addr_isany(&(cpcb->local_ip)) ||        if (ip_addr_isany(&(cpcb->local_ip)) ||
277           ip_addr_isany(ipaddr) ||     ip_addr_isany(ipaddr) ||
278           ip_addr_cmp(&(cpcb->local_ip), ipaddr)) {     ip_addr_cmp(&(cpcb->local_ip), ipaddr)) {
279          return ERR_USE;    return ERR_USE;
280        }        }
281      }      }
282    }    }
# Line 352  tcp_recved(struct tcp_pcb *pcb, u16_t le Line 352  tcp_recved(struct tcp_pcb *pcb, u16_t le
352      tcp_ack(pcb);      tcp_ack(pcb);
353    }    }
354    DEBUGF(TCP_DEBUG, ("tcp_recved: recveived %u bytes, wnd %u (%u).\n",    DEBUGF(TCP_DEBUG, ("tcp_recved: recveived %u bytes, wnd %u (%u).\n",
355                       len, pcb->rcv_wnd, TCP_WND - pcb->rcv_wnd));           len, pcb->rcv_wnd, TCP_WND - pcb->rcv_wnd));
356  }  }
357  /*-----------------------------------------------------------------------------------*/  /*-----------------------------------------------------------------------------------*/
358  /*  /*
# Line 405  tcp_new_port(void) Line 405  tcp_new_port(void)
405  /*-----------------------------------------------------------------------------------*/  /*-----------------------------------------------------------------------------------*/
406  err_t  err_t
407  tcp_connect(struct tcp_pcb *pcb, struct ip_addr *ipaddr, u16_t port,  tcp_connect(struct tcp_pcb *pcb, struct ip_addr *ipaddr, u16_t port,
408              err_t (* connected)(void *arg, struct tcp_pcb *tpcb, err_t err))        err_t (* connected)(void *arg, struct tcp_pcb *tpcb, err_t err))
409  {  {
410    u32_t optdata;    u32_t optdata;
411    err_t ret;    err_t ret;
# Line 439  tcp_connect(struct tcp_pcb *pcb, struct Line 439  tcp_connect(struct tcp_pcb *pcb, struct
439        
440    /* Build an MSS option */    /* Build an MSS option */
441    optdata = htonl(((u32_t)2 << 24) |    optdata = htonl(((u32_t)2 << 24) |
442                    ((u32_t)4 << 16) |        ((u32_t)4 << 16) |
443                    (((u32_t)pcb->mss / 256) << 8) |        (((u32_t)pcb->mss / 256) << 8) |
444                    (pcb->mss & 255));        (pcb->mss & 255));
445    
446    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);
447    if (ret == ERR_OK) {    if (ret == ERR_OK) {
# Line 539  tcp_slowtmr(void) Line 539  tcp_slowtmr(void)
539      /* Check if this PCB has stayed too long in SYN-RCVD */      /* Check if this PCB has stayed too long in SYN-RCVD */
540      if (pcb->state == SYN_RCVD) {      if (pcb->state == SYN_RCVD) {
541        if ((u32_t)(tcp_ticks - pcb->tmr) >        if ((u32_t)(tcp_ticks - pcb->tmr) >
542           TCP_SYN_RCVD_TIMEOUT / TCP_SLOW_INTERVAL) {     TCP_SYN_RCVD_TIMEOUT / TCP_SLOW_INTERVAL) {
543          ++pcb_remove;          ++pcb_remove;
544          DEBUGF(TCP_DEBUG, ("tcp_slowtmr: removing pcb stuck in SYN-RCVD\n"));          DEBUGF(TCP_DEBUG, ("tcp_slowtmr: removing pcb stuck in SYN-RCVD\n"));
545        }        }
# Line 551  tcp_slowtmr(void) Line 551  tcp_slowtmr(void)
551        tcp_pcb_purge(pcb);              tcp_pcb_purge(pcb);      
552        /* Remove PCB from tcp_active_pcbs list. */        /* Remove PCB from tcp_active_pcbs list. */
553        if (prev != NULL) {        if (prev != NULL) {
554          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);
555          prev->next = pcb->next;          prev->next = pcb->next;
556        } else {        } else {
557          /* This PCB was the first. */          /* This PCB was the first. */
# Line 569  tcp_slowtmr(void) Line 569  tcp_slowtmr(void)
569        /* We check if we should poll the connection. */        /* We check if we should poll the connection. */
570        ++pcb->polltmr;        ++pcb->polltmr;
571        if (pcb->polltmr >= pcb->pollinterval) {        if (pcb->polltmr >= pcb->pollinterval) {
572          pcb->polltmr = 0;    pcb->polltmr = 0;
573          DEBUGF(TCP_DEBUG, ("tcp_slowtmr: polling application\n"));          DEBUGF(TCP_DEBUG, ("tcp_slowtmr: polling application\n"));
574          TCP_EVENT_POLL(pcb, err);    TCP_EVENT_POLL(pcb, err);
575          if (err == ERR_OK) {    if (err == ERR_OK) {
576            tcp_output(pcb);      tcp_output(pcb);
577          }    }
578        }        }
579                
580        prev = pcb;        prev = pcb;
# Line 602  tcp_slowtmr(void) Line 602  tcp_slowtmr(void)
602        tcp_pcb_purge(pcb);              tcp_pcb_purge(pcb);      
603        /* Remove PCB from tcp_tw_pcbs list. */        /* Remove PCB from tcp_tw_pcbs list. */
604        if (prev != NULL) {        if (prev != NULL) {
605          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);
606          prev->next = pcb->next;          prev->next = pcb->next;
607        } else {        } else {
608          /* This PCB was the first. */          /* This PCB was the first. */
# Line 761  tcp_kill_prio(u8_t prio) Line 761  tcp_kill_prio(u8_t prio)
761    }    }
762    if (inactive != NULL) {    if (inactive != NULL) {
763      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",
764                         (void *)inactive, inactivity));             (void *)inactive, inactivity));
765      tcp_abort(inactive);      tcp_abort(inactive);
766    }          }      
767  }  }
# Line 783  tcp_kill_timewait(void) Line 783  tcp_kill_timewait(void)
783    }    }
784    if (inactive != NULL) {    if (inactive != NULL) {
785      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",
786                         (void *)inactive, inactivity));             (void *)inactive, inactivity));
787      tcp_abort(inactive);      tcp_abort(inactive);
788    }          }      
789  }  }
# Line 875  tcp_arg(struct tcp_pcb *pcb, void *arg) Line 875  tcp_arg(struct tcp_pcb *pcb, void *arg)
875  #if LWIP_CALLBACK_API  #if LWIP_CALLBACK_API
876  void  void
877  tcp_recv(struct tcp_pcb *pcb,  tcp_recv(struct tcp_pcb *pcb,
878           err_t (* recv)(void *arg, struct tcp_pcb *tpcb, struct pbuf *p, err_t err))     err_t (* recv)(void *arg, struct tcp_pcb *tpcb, struct pbuf *p, err_t err))
879  {  {
880    pcb->recv = recv;    pcb->recv = recv;
881  }  }
# Line 892  tcp_recv(struct tcp_pcb *pcb, Line 892  tcp_recv(struct tcp_pcb *pcb,
892  #if LWIP_CALLBACK_API  #if LWIP_CALLBACK_API
893  void  void
894  tcp_sent(struct tcp_pcb *pcb,  tcp_sent(struct tcp_pcb *pcb,
895           err_t (* sent)(void *arg, struct tcp_pcb *tpcb, u16_t len))     err_t (* sent)(void *arg, struct tcp_pcb *tpcb, u16_t len))
896  {  {
897    pcb->sent = sent;    pcb->sent = sent;
898  }  }
# Line 909  tcp_sent(struct tcp_pcb *pcb, Line 909  tcp_sent(struct tcp_pcb *pcb,
909  #if LWIP_CALLBACK_API  #if LWIP_CALLBACK_API
910  void  void
911  tcp_err(struct tcp_pcb *pcb,  tcp_err(struct tcp_pcb *pcb,
912           void (* errf)(void *arg, err_t err))     void (* errf)(void *arg, err_t err))
913  {  {
914    pcb->errf = errf;    pcb->errf = errf;
915  }  }
# Line 926  tcp_err(struct tcp_pcb *pcb, Line 926  tcp_err(struct tcp_pcb *pcb,
926  /*-----------------------------------------------------------------------------------*/  /*-----------------------------------------------------------------------------------*/
927  void  void
928  tcp_poll(struct tcp_pcb *pcb,  tcp_poll(struct tcp_pcb *pcb,
929           err_t (* poll)(void *arg, struct tcp_pcb *tpcb), u8_t interval)     err_t (* poll)(void *arg, struct tcp_pcb *tpcb), u8_t interval)
930  {  {
931  #if LWIP_CALLBACK_API  #if LWIP_CALLBACK_API
932    pcb->poll = poll;    pcb->poll = poll;
# Line 945  tcp_poll(struct tcp_pcb *pcb, Line 945  tcp_poll(struct tcp_pcb *pcb,
945  #if LWIP_CALLBACK_API  #if LWIP_CALLBACK_API
946  void  void
947  tcp_accept(struct tcp_pcb *pcb,  tcp_accept(struct tcp_pcb *pcb,
948             err_t (* accept)(void *arg, struct tcp_pcb *newpcb, err_t err))       err_t (* accept)(void *arg, struct tcp_pcb *newpcb, err_t err))
949  {  {
950    ((struct tcp_pcb_listen *)pcb)->accept = accept;    ((struct tcp_pcb_listen *)pcb)->accept = accept;
951  }  }
# Line 1042  tcp_debug_print(struct tcp_hdr *tcphdr) Line 1042  tcp_debug_print(struct tcp_hdr *tcphdr)
1042    DEBUGF(TCP_DEBUG, ("TCP header:\n"));    DEBUGF(TCP_DEBUG, ("TCP header:\n"));
1043    DEBUGF(TCP_DEBUG, ("+-------------------------------+\n"));    DEBUGF(TCP_DEBUG, ("+-------------------------------+\n"));
1044    DEBUGF(TCP_DEBUG, ("|      %04x     |      %04x     | (src port, dest port)\n",    DEBUGF(TCP_DEBUG, ("|      %04x     |      %04x     | (src port, dest port)\n",
1045                       tcphdr->src, tcphdr->dest));           tcphdr->src, tcphdr->dest));
1046    DEBUGF(TCP_DEBUG, ("+-------------------------------+\n"));    DEBUGF(TCP_DEBUG, ("+-------------------------------+\n"));
1047    DEBUGF(TCP_DEBUG, ("|            %08lu           | (seq no)\n",    DEBUGF(TCP_DEBUG, ("|            %08lu           | (seq no)\n",
1048                              tcphdr->seqno));            tcphdr->seqno));
1049    DEBUGF(TCP_DEBUG, ("+-------------------------------+\n"));    DEBUGF(TCP_DEBUG, ("+-------------------------------+\n"));
1050    DEBUGF(TCP_DEBUG, ("|            %08lu           | (ack no)\n",    DEBUGF(TCP_DEBUG, ("|            %08lu           | (ack no)\n",
1051                       tcphdr->ackno));           tcphdr->ackno));
1052    DEBUGF(TCP_DEBUG, ("+-------------------------------+\n"));    DEBUGF(TCP_DEBUG, ("+-------------------------------+\n"));
1053    DEBUGF(TCP_DEBUG, ("| %2u |    |%u%u%u%u%u|    %5u      | (offset, flags (",    DEBUGF(TCP_DEBUG, ("| %2u |    |%u%u%u%u%u|    %5u      | (offset, flags (",
1054                           TCPH_OFFSET(tcphdr),         TCPH_OFFSET(tcphdr),
1055                       TCPH_FLAGS(tcphdr) >> 4 & 1,           TCPH_FLAGS(tcphdr) >> 4 & 1,
1056                       TCPH_FLAGS(tcphdr) >> 4 & 1,           TCPH_FLAGS(tcphdr) >> 4 & 1,
1057                       TCPH_FLAGS(tcphdr) >> 3 & 1,           TCPH_FLAGS(tcphdr) >> 3 & 1,
1058                       TCPH_FLAGS(tcphdr) >> 2 & 1,           TCPH_FLAGS(tcphdr) >> 2 & 1,
1059                       TCPH_FLAGS(tcphdr) >> 1 & 1,           TCPH_FLAGS(tcphdr) >> 1 & 1,
1060                       TCPH_FLAGS(tcphdr) & 1,           TCPH_FLAGS(tcphdr) & 1,
1061                       tcphdr->wnd));           tcphdr->wnd));
1062    tcp_debug_print_flags(TCPH_FLAGS(tcphdr));    tcp_debug_print_flags(TCPH_FLAGS(tcphdr));
1063    DEBUGF(TCP_DEBUG, ("), win)\n"));    DEBUGF(TCP_DEBUG, ("), win)\n"));
1064    DEBUGF(TCP_DEBUG, ("+-------------------------------+\n"));    DEBUGF(TCP_DEBUG, ("+-------------------------------+\n"));
1065    DEBUGF(TCP_DEBUG, ("|    0x%04x     |     %5u     | (chksum, urgp)\n",    DEBUGF(TCP_DEBUG, ("|    0x%04x     |     %5u     | (chksum, urgp)\n",
1066                       ntohs(tcphdr->chksum), ntohs(tcphdr->urgp)));           ntohs(tcphdr->chksum), ntohs(tcphdr->urgp)));
1067    DEBUGF(TCP_DEBUG, ("+-------------------------------+\n"));    DEBUGF(TCP_DEBUG, ("+-------------------------------+\n"));
1068  }  }
1069  /*-----------------------------------------------------------------------------------*/  /*-----------------------------------------------------------------------------------*/

Legend:
Removed from v.1.28  
changed lines
  Added in v.1.29

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