1 Star 0 Fork 0

Von / tcp_stack

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
tcp_timer.c 1.12 KB
一键复制 编辑 原始数据 按行查看 历史
Roccoon 提交于 2017-11-03 12:44 . Initialize this project.
#include "tcp.h"
#include "tcp_timer.h"
#include "tcp_sock.h"
#include <unistd.h>
static struct list_head timer_list;
// scan the timer_list, find the tcp sock which stays for at 2*MSL, release it
void tcp_scan_timer_list()
{
struct tcp_sock *tsk;
struct tcp_timer *t, *q;
list_for_each_entry_safe(t, q, &timer_list, list) {
t->timeout -= TCP_TIMER_SCAN_INTERVAL;
if (t->timeout <= 0) {
list_delete_entry(&t->list);
// only support time wait now
tsk = timewait_to_tcp_sock(t);
if (! tsk->parent)
tcp_bind_unhash(tsk);
tcp_set_state(tsk, TCP_CLOSED);
free_tcp_sock(tsk);
}
}
}
// set the timewait timer of a tcp sock, by adding the timer into timer_list
void tcp_set_timewait_timer(struct tcp_sock *tsk)
{
struct tcp_timer *timer = &tsk->timewait;
timer->type = 0;
timer->timeout = TCP_TIMEWAIT_TIMEOUT;
list_add_tail(&timer->list, &timer_list);
tcp_sock_inc_ref_cnt(tsk);
}
// scan the timer_list periodically by calling tcp_scan_timer_list
void *tcp_timer_thread(void *arg)
{
init_list_head(&timer_list);
while (1) {
usleep(TCP_TIMER_SCAN_INTERVAL);
tcp_scan_timer_list();
}
return NULL;
}
1
https://gitee.com/Von-walliam/tcp_stack.git
git@gitee.com:Von-walliam/tcp_stack.git
Von-walliam
tcp_stack
tcp_stack
master

搜索帮助