📄 cache.cc
字号:
/******************************************************************* Copyright (C) 2004 Thomas Kunz, CRC Canada, BCAST for IPv4. DISTRIBUTED WITH NO WARRANTY, EXPRESS OR IMPLIED. See the GNU Library General Public License (file COPYING in the MANET_multicast directory) for conditions of use and redistribution.*********************************************************************//* * Functions to manage a cache of packets. The cache is of fixed size * (determined at creation time) and managed in FIFO order. */#include "MANET_multicast/cache.h"/* Constructor */PacketCache::PacketCache(int size) { cache = new Packet*[size]; assert(cache); for (int i = 0; i < size; i++){ cache[i] = (Packet *)NULL; } cache_size = size; current = 0;}/* Unique ID Management Functions*/voidPacketCache::packet_insert(Packet* p) { if (cache[current] != NULL) { Packet::free(cache[current]); } cache[current] = p->copy(); current = (current + 1) % cache_size;}Packet*PacketCache::packet_lookup(nsaddr_t src, u_int32_t seqno) {int i = 0; // Search the cache for a match of source and bid for (i = 0; i < cache_size; i++) { if (cache[i] != NULL) { struct hdr_ip *ih = HDR_IP(cache[i]); struct hdr_rtp *rh = HDR_RTP(cache[i]); nsaddr_t p_src = ih->saddr(); unsigned int p_seqno = rh->seqno_; if (src == p_src && seqno == p_seqno) { return (cache[i]); } } } return ((Packet*)NULL);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -