Lwip 断连,连接几次后不通及偶尔不通的问题.
来源:互联网 发布:非涉密网络监测设备? 编辑:程序博客网 时间:2024/06/06 01:22
新加这个函数,并在tcp_in函数里调用一下.出现不通的原因是在网络状态不流畅的情况下,连续连接N次后,LWIP默认不在连接,新建一个变量
//自己做一个函数
struct tcp_pcb *tcp_find_distant(void)
{#if LWIP_AUTO_FREE_ACTIVE_PCB
struct tcp_pcb *pcb = NULL;
struct tcp_pcb *last_pcb = NULL;
unsigned long last_tick = get_sys_tick();
int pcb_num = 0; //当前一共有几个 配置宏 MEMP_NUM_TCP_PCB
for(pcb = tcp_active_pcbs; pcb != NULL; pcb = pcb->next)
{
pcb_num++;
}
if(pcb_num>=MEMP_NUM_TCP_PCB)
{
for(pcb = tcp_active_pcbs; pcb != NULL; pcb = pcb->next)
{
if(last_tick>pcb->last_tick)
{
last_tick = pcb->last_tick;
last_pcb = pcb;
}
}
}
return last_pcb;
#else
return NULL;
#endif
}
void
tcp_input(struct pbuf *p, struct netif *inp)
{
......
for(lpcb = tcp_listen_pcbs.listen_pcbs; lpcb != NULL; lpcb = lpcb->next) {
if ((ip_addr_isany(&(lpcb->local_ip)) ||
ip_addr_cmp(&(lpcb->local_ip), &(iphdr->dest))) &&
lpcb->local_port == tcphdr->dest) {
/* Move this PCB to the front of the list so that subsequent
lookups will be faster (we exploit locality in TCP segment
arrivals). */
if (prev != NULL) {
((struct tcp_pcb_listen *)prev)->next = lpcb->next;
/* our successor is the remainder of the listening list */
lpcb->next = tcp_listen_pcbs.listen_pcbs;
/* put this listening pcb at the head of the listening list */
tcp_listen_pcbs.listen_pcbs = lpcb;
}
LWIP_DEBUGF(TCP_INPUT_DEBUG, ("tcp_input: packed for LISTENing connection.\n"));
//新加的代码
//无法申请到内存块,说明当前已连接的PCB已达到上限,释放最近的active中的PCB块
if(tcp_listen_input(lpcb)==ERR_MEM)
{
struct tcp_pcb *destroy_pcb = tcp_find_distant();
if(destroy_pcb!=NULL)
{
tcp_abandon(destroy_pcb, 1);
//tcp_close(destroy_pcb);
goto LBL_RESTART;
}
}
pbuf_free(p);
return;
}
prev = (struct tcp_pcb *)lpcb;
}
}
- Lwip 断连,连接几次后不通及偶尔不通的问题.
- 常见的开发板与主机连不通问题
- 本机链接虚拟机连不通的问题
- net连不通主机
- cisco1841更改IP后,VPN不通的问题
- VMware ssh不通的问题
- STM32移植LWIP网线热插入网络不通的解决办法
- 解决Sql Sever2008安装后,连接EAS服务器出现端口不通问题
- 网络连接不通的处理方法
- 本地连接不通的情况下连接vmbox
- SOCKET 连接不通
- vmware centos7 桥接的网络--连不通
- 一个单片机的问题,真想不通
- 关于oracle远程1521不通的问题
- CentOS系统时间不通引发的问题
- 解决虚拟机ping不通主机的问题
- 家庭无线网络局域网PING不通的问题
- ping 不通百度问题的解决
- IR复习(1)
- Sublime Text 3.0-3059 MAC 、windows、Linux下的破解方法
- 全屏显示. Tween动画
- python string模块
- hdoj 2209 翻纸牌游戏(BFS + 位运算)
- Lwip 断连,连接几次后不通及偶尔不通的问题.
- c++中类的公有和私有初探01
- AJAX组件-dwr 的部署与实现
- Android TableLayout表格布局详解
- 过迟明白需求
- objective-c语法
- android std::string(NULL) crash
- UVa 10315 Poker Hands
- JavaScript类和继承:constructor属性