task #7497: Sort lists (pcb, netif, ...) for faster access UDP: move a (connected) pcb selected for input to the front of the list of pcbs so that it is found faster next time. Same for RAW pcbs that have eaten a packet.

This commit is contained in:
goldsimon 2007-11-30 09:44:18 +00:00
parent cedd5c21e6
commit b28cd02149
3 changed files with 28 additions and 2 deletions

View File

@ -19,6 +19,12 @@ HISTORY
++ New features:
2007-11-30 Simon Goldschmidt
* udp.c, raw.c: task #7497: Sort lists (pcb, netif, ...) for faster access
UDP: move a (connected) pcb selected for input to the front of the list of
pcbs so that it is found faster next time. Same for RAW pcbs that have eaten
a packet.
2007-11-28 Simon Goldschmidt
* etharp.c, stats.c, stats.h, opt.h: Introduced ETHARP_STATS

View File

@ -77,7 +77,7 @@ static struct raw_pcb *raw_pcbs;
u8_t
raw_input(struct pbuf *p, struct netif *inp)
{
struct raw_pcb *pcb;
struct raw_pcb *pcb, *prev;
struct ip_hdr *iphdr;
s16_t proto;
u8_t eaten = 0;
@ -87,6 +87,7 @@ raw_input(struct pbuf *p, struct netif *inp)
iphdr = p->payload;
proto = IPH_PROTO(iphdr);
prev = NULL;
pcb = raw_pcbs;
/* loop through all raw pcbs until the packet is eaten by one */
/* this allows multiple pcbs to match against the packet by design */
@ -100,11 +101,19 @@ raw_input(struct pbuf *p, struct netif *inp)
/* receive function ate the packet */
p = NULL;
eaten = 1;
if (prev != NULL) {
/* move the pcb to the front of raw_pcbs so that is
found faster next time */
prev->next = pcb->next;
pcb->next = raw_pcbs;
raw_pcbs = pcb;
}
}
}
/* no receive callback function was set for this raw PCB */
/* drop the packet */
}
prev = pcb;
pcb = pcb->next;
}
return eaten;

View File

@ -85,7 +85,7 @@ void
udp_input(struct pbuf *p, struct netif *inp)
{
struct udp_hdr *udphdr;
struct udp_pcb *pcb;
struct udp_pcb *pcb, *prev;
struct udp_pcb *uncon_pcb;
struct ip_hdr *iphdr;
u16_t src, dest;
@ -149,6 +149,7 @@ udp_input(struct pbuf *p, struct netif *inp)
} else
#endif /* LWIP_DHCP */
{
prev = NULL;
local_match = 0;
uncon_pcb = NULL;
/* Iterate through the UDP pcb list for a matching pcb.
@ -187,8 +188,18 @@ udp_input(struct pbuf *p, struct netif *inp)
(ip_addr_isany(&pcb->remote_ip) ||
ip_addr_cmp(&(pcb->remote_ip), &(iphdr->src)))) {
/* the first fully matching PCB */
if (prev != NULL) {
/* move the pcb to the front of udp_pcbs so that is
found faster next time */
prev->next = pcb->next;
pcb->next = udp_pcbs;
udp_pcbs = pcb;
} else {
UDP_STATS_INC(udp.cachehit);
}
break;
}
prev = pcb;
}
/* no fully matching pcb found? then look for an unconnected pcb */
if (pcb == NULL) {