Merged listen_pcb union fix from HEAD.

This commit is contained in:
likewise 2004-04-23 15:43:44 +00:00
parent 3cf8dfa55e
commit a52d3548a0
4 changed files with 26 additions and 17 deletions

View File

@ -62,7 +62,9 @@ const u8_t tcp_backoff[13] =
{ 1, 2, 3, 4, 5, 6, 7, 7, 7, 7, 7, 7, 7}; { 1, 2, 3, 4, 5, 6, 7, 7, 7, 7, 7, 7, 7};
/* The TCP PCB lists. */ /* The TCP PCB lists. */
struct tcp_pcb_listen *tcp_listen_pcbs; /* List of all TCP PCBs in LISTEN state. */
/* List of all TCP PCBs in LISTEN state. */
union tcp_listen_pcbs_t tcp_listen_pcbs;
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
state in which they accept or send state in which they accept or send
data. */ data. */
@ -85,7 +87,7 @@ void
tcp_init(void) tcp_init(void)
{ {
/* Clear globals. */ /* Clear globals. */
tcp_listen_pcbs = NULL; tcp_listen_pcbs.listen_pcbs = NULL;
tcp_active_pcbs = NULL; tcp_active_pcbs = NULL;
tcp_tw_pcbs = NULL; tcp_tw_pcbs = NULL;
tcp_tmp_pcb = NULL; tcp_tmp_pcb = NULL;
@ -136,7 +138,7 @@ tcp_close(struct tcp_pcb *pcb)
switch (pcb->state) { switch (pcb->state) {
case LISTEN: case LISTEN:
err = ERR_OK; err = ERR_OK;
tcp_pcb_remove((struct tcp_pcb **)&tcp_listen_pcbs, pcb); tcp_pcb_remove((struct tcp_pcb **)&tcp_listen_pcbs.pcbs, pcb);
memp_free(MEMP_TCP_PCB_LISTEN, pcb); memp_free(MEMP_TCP_PCB_LISTEN, pcb);
pcb = NULL; pcb = NULL;
break; break;
@ -251,7 +253,7 @@ tcp_bind(struct tcp_pcb *pcb, struct ip_addr *ipaddr, u16_t port)
} }
#if SO_REUSE == 0 #if SO_REUSE == 0
/* Check if the address already is in use. */ /* Check if the address already is in use. */
for(cpcb = (struct tcp_pcb *)tcp_listen_pcbs; for(cpcb = (struct tcp_pcb *)tcp_listen_pcbs.pcbs;
cpcb != NULL; cpcb = cpcb->next) { cpcb != NULL; cpcb = cpcb->next) {
if (cpcb->local_port == port) { if (cpcb->local_port == port) {
if (ip_addr_isany(&(cpcb->local_ip)) || if (ip_addr_isany(&(cpcb->local_ip)) ||
@ -284,7 +286,7 @@ tcp_bind(struct tcp_pcb *pcb, struct ip_addr *ipaddr, u16_t port)
When the two options aren't set and specified port is already bound, ERR_USE is returned saying that When the two options aren't set and specified port is already bound, ERR_USE is returned saying that
address is already in use. */ address is already in use. */
for(cpcb = (struct tcp_pcb *)tcp_listen_pcbs; cpcb != NULL; cpcb = cpcb->next) { for(cpcb = (struct tcp_pcb *)tcp_listen_pcbs.pcbs; cpcb != NULL; cpcb = cpcb->next) {
if(cpcb->local_port == port) { if(cpcb->local_port == port) {
if(ip_addr_cmp(&(cpcb->local_ip), ipaddr)) { if(ip_addr_cmp(&(cpcb->local_ip), ipaddr)) {
if(pcb->so_options & SOF_REUSEPORT) { if(pcb->so_options & SOF_REUSEPORT) {
@ -421,7 +423,7 @@ tcp_listen(struct tcp_pcb *pcb)
#if LWIP_CALLBACK_API #if LWIP_CALLBACK_API
lpcb->accept = tcp_accept_null; lpcb->accept = tcp_accept_null;
#endif /* LWIP_CALLBACK_API */ #endif /* LWIP_CALLBACK_API */
TCP_REG(&tcp_listen_pcbs, lpcb); TCP_REG(&tcp_listen_pcbs.listen_pcbs, lpcb);
return (struct tcp_pcb *)lpcb; return (struct tcp_pcb *)lpcb;
} }
@ -493,7 +495,7 @@ tcp_new_port(void)
goto again; goto again;
} }
} }
for(pcb = (struct tcp_pcb *)tcp_listen_pcbs; pcb != NULL; pcb = pcb->next) { for(pcb = (struct tcp_pcb *)tcp_listen_pcbs.pcbs; pcb != NULL; pcb = pcb->next) {
if (pcb->local_port == port) { if (pcb->local_port == port) {
goto again; goto again;
} }
@ -1263,7 +1265,7 @@ tcp_debug_print_pcbs(void)
tcp_debug_print_state(pcb->state); tcp_debug_print_state(pcb->state);
} }
LWIP_DEBUGF(TCP_DEBUG, ("Listen PCB states:\n")); LWIP_DEBUGF(TCP_DEBUG, ("Listen PCB states:\n"));
for(pcb = (struct tcp_pcb *)tcp_listen_pcbs; pcb != NULL; pcb = pcb->next) { for(pcb = (struct tcp_pcb *)tcp_listen_pcbs.pcbs; pcb != NULL; pcb = pcb->next) {
LWIP_DEBUGF(TCP_DEBUG, ("Local port %u, foreign port %u snd_nxt %lu rcv_nxt %lu ", LWIP_DEBUGF(TCP_DEBUG, ("Local port %u, foreign port %u snd_nxt %lu rcv_nxt %lu ",
pcb->local_port, pcb->remote_port, pcb->local_port, pcb->remote_port,
pcb->snd_nxt, pcb->rcv_nxt)); pcb->snd_nxt, pcb->rcv_nxt));

View File

@ -254,7 +254,7 @@ tcp_input(struct pbuf *p, struct netif *inp)
/* Finally, if we still did not get a match, we check all PCBs that /* Finally, if we still did not get a match, we check all PCBs that
are LISTENing for incoming connections. */ are LISTENing for incoming connections. */
prev = NULL; prev = NULL;
for(lpcb = tcp_listen_pcbs; lpcb != NULL; lpcb = lpcb->next) { for(lpcb = tcp_listen_pcbs.listen_pcbs; lpcb != NULL; lpcb = lpcb->next) {
if ((ip_addr_isany(&(lpcb->local_ip)) || if ((ip_addr_isany(&(lpcb->local_ip)) ||
ip_addr_cmp(&(lpcb->local_ip), &(iphdr->dest))) && ip_addr_cmp(&(lpcb->local_ip), &(iphdr->dest))) &&
lpcb->local_port == tcphdr->dest) { lpcb->local_port == tcphdr->dest) {
@ -264,9 +264,9 @@ tcp_input(struct pbuf *p, struct netif *inp)
if (prev != NULL) { if (prev != NULL) {
((struct tcp_pcb_listen *)prev)->next = lpcb->next; ((struct tcp_pcb_listen *)prev)->next = lpcb->next;
/* our successor is the remainder of the listening list */ /* our successor is the remainder of the listening list */
lpcb->next = tcp_listen_pcbs; lpcb->next = tcp_listen_pcbs.listen_pcbs;
/* put this listening pcb at the head of the listening list */ /* put this listening pcb at the head of the listening list */
tcp_listen_pcbs = lpcb; tcp_listen_pcbs.listen_pcbs = lpcb;
} }
LWIP_DEBUGF(TCP_INPUT_DEBUG, ("tcp_input: packed for LISTENing connection.\n")); LWIP_DEBUGF(TCP_INPUT_DEBUG, ("tcp_input: packed for LISTENing connection.\n"));

View File

@ -63,8 +63,6 @@
/* Forward declarations.*/ /* Forward declarations.*/
static void tcp_output_segment(struct tcp_seg *seg, struct tcp_pcb *pcb); static void tcp_output_segment(struct tcp_seg *seg, struct tcp_pcb *pcb);
err_t err_t
tcp_send_ctrl(struct tcp_pcb *pcb, u8_t flags) tcp_send_ctrl(struct tcp_pcb *pcb, u8_t flags)
{ {
@ -72,6 +70,14 @@ tcp_send_ctrl(struct tcp_pcb *pcb, u8_t flags)
} }
/*
* NB. tcp_write() enqueues data for sending, but does not send it
* straight away. It waits in the expectation of more data being sent
* soon (as it can send them more efficiently by combining them
* together). To prompt the system to send data now, call
* tcp_output() after calling tcp_write().
*/
err_t err_t
tcp_write(struct tcp_pcb *pcb, const void *arg, u16_t len, u8_t copy) tcp_write(struct tcp_pcb *pcb, const void *arg, u16_t len, u8_t copy)
{ {
@ -403,7 +409,6 @@ tcp_output(struct tcp_pcb *pcb)
tcphdr->chksum = inet_chksum_pseudo(p, &(pcb->local_ip), &(pcb->remote_ip), tcphdr->chksum = inet_chksum_pseudo(p, &(pcb->local_ip), &(pcb->remote_ip),
IP_PROTO_TCP, p->tot_len); IP_PROTO_TCP, p->tot_len);
ip_output(p, &(pcb->local_ip), &(pcb->remote_ip), pcb->ttl, pcb->tos, ip_output(p, &(pcb->local_ip), &(pcb->remote_ip), pcb->ttl, pcb->tos,
IP_PROTO_TCP); IP_PROTO_TCP);
pbuf_free(p); pbuf_free(p);

View File

@ -40,8 +40,6 @@
#include "lwip/ip.h" #include "lwip/ip.h"
#include "lwip/icmp.h" #include "lwip/icmp.h"
#include "lwip/sys.h"
#include "lwip/err.h" #include "lwip/err.h"
struct tcp_pcb; struct tcp_pcb;
@ -457,7 +455,11 @@ void tcp_timer_needed(void);
#endif #endif
/* The TCP PCB lists. */ /* The TCP PCB lists. */
extern struct tcp_pcb_listen *tcp_listen_pcbs; /* List of all TCP PCBs in LISTEN state. */ union tcp_listen_pcbs_t { /* List of all TCP PCBs in LISTEN state. */
struct tcp_pcb_listen *listen_pcbs;
struct tcp_pcb *pcbs;
};
extern union tcp_listen_pcbs_t tcp_listen_pcbs;
extern struct tcp_pcb *tcp_active_pcbs; /* List of all TCP PCBs that are in a extern struct tcp_pcb *tcp_active_pcbs; /* List of all TCP PCBs that are in a
state in which they accept or send state in which they accept or send
data. */ data. */