tcptimer.c

来自「很不错的tcpip源码, 尤其是针对嵌入式系统编程来说是个非常不错的选择」· C语言 代码 · 共 57 行

C
57
字号
/* TCP timeout routines
 */
#include <stdio.h>
#include "global.h"
#include "mbuf.h"
#include "timer.h"
#include "netuser.h"
#include "internet.h"
#include "tcp.h"

/* Timer timeout */
void
tcp_timeout(p)
void *p;
{
	register struct tcb *tcb;
	int32 ptrsave;

	tcb = p;
	if(tcb == NULL)
		return;

	/* Make sure the timer has stopped (we might have been kicked) */
	stop_timer(&tcb->timer);

	switch(tcb->state){
	case TCP_TIME_WAIT:	/* 2MSL timer has expired */
		close_self(tcb,NORMAL);
		break;
	default:		/* Retransmission timer has expired */
		tcb->timeouts++;
		tcb->flags.retran = 1;	/* Indicate > 1  transmission */
		tcb->backoff++;
		/* Reduce slowstart threshold to half current window */
		tcb->ssthresh = tcb->cwind / 2;
		tcb->ssthresh = max(tcb->ssthresh,tcb->mss);
		/* Shrink congestion window to 1 packet */
		tcb->cwind = tcb->mss;
		/* Retransmit just the oldest unacked packet */
		ptrsave = tcb->snd.ptr;
		tcb->snd.ptr = tcb->snd.una;
		tcp_output(tcb);
		tcb->snd.ptr = ptrsave;
	}
}
/* Backoff function - the subject of much research */
int32
backoff(n)
int n;
{
	if(n > 31)
		n = 31;	/* Prevent truncation to zero */

	return 1L << n;	/* Binary exponential back off */
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?