代码拉取完成,页面将自动刷新
同步操作将从 yuanhack/sarudp 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
/* include rtt1 */
#include "unprtt.h"
#include "wrapfunc.h"
#include <stdlib.h>
#include <stdio.h>
int rtt_d_flag = 1; /* debug flag; can be set by caller */
/*
* Calculate the RTO value based on current estimators:
* smoothed RTT plus four times the deviation
*/
#define RTT_RTOCALC(ptr) ((ptr)->rtt_srtt + (4.0 * (ptr)->rtt_rttvar))
static float
rtt_minmax(float rto)
{
if (rto < RTT_RXTMIN)
rto = RTT_RXTMIN;
else if (rto > RTT_RXTMAX)
rto = RTT_RXTMAX;
return(rto);
}
void
rtt_init(struct rtt_info *ptr, uint8_t retry)
{
struct timeval tv;
Gettimeofday(&tv, NULL);
ptr->rtt_base = tv.tv_sec; /* # sec since 1/1/1970 at start */
ptr->rtt_retry = retry;
ptr->rtt_rtt = 0;
ptr->rtt_srtt = 0;
ptr->rtt_rttvar = 0.75;
ptr->rtt_rto = rtt_minmax(RTT_RTOCALC(ptr));
/* first RTO at (srtt + (4 * rttvar)) = 3 seconds */
}
/* end rtt1 */
/*
* Return the current timestamp.
* Our timestamps are 32-bit integers that count milliseconds since
* rtt_init() was called.
*/
/* include rtt_ts */
uint32_t
rtt_ts(struct rtt_info *ptr)
{
uint32_t ts;
struct timeval tv;
Gettimeofday(&tv, NULL);
ts = ((tv.tv_sec - ptr->rtt_base) * 1000) + (tv.tv_usec / 1000);
return(ts);
}
void
rtt_newpack(struct rtt_info *ptr)
{
ptr->rtt_nrexmt = 0;
}
int
rtt_start(struct rtt_info *ptr)
{
return((int) (ptr->rtt_rto + 0.5)); /* round float to int */
/* 4return value can be used as: alarm(rtt_start(&foo)) */
}
/* end rtt_ts */
/*
* A response was received.
* Stop the timer and update the appropriate values in the structure
* based on this packet's RTT. We calculate the RTT, then update the
* estimators of the RTT and its mean deviation.
* This function should be called right after turning off the
* timer with alarm(0), or right after a timeout occurs.
*/
/* include rtt_stop */
void
rtt_stop(struct rtt_info *ptr, uint32_t ms)
{
double delta;
ptr->rtt_rtt = ms / 1000.0; /* measured RTT in seconds */
/*
* Update our estimators of RTT and mean deviation of RTT.
* See Jacobson's SIGCOMM '88 paper, Appendix A, for the details.
* We use floating point here for simplicity.
*/
delta = ptr->rtt_rtt - ptr->rtt_srtt;
ptr->rtt_srtt += delta / 8; /* g = 1/8 */
if (delta < 0.0)
delta = -delta; /* |delta| */
ptr->rtt_rttvar += (delta - ptr->rtt_rttvar) / 4; /* h = 1/4 */
ptr->rtt_rto = rtt_minmax(RTT_RTOCALC(ptr));
}
/* end rtt_stop */
/*
* A timeout has occurred.
* Return -1 if it's time to give up, else return 0.
*/
/* include rtt_timeout */
int
rtt_timeout(struct rtt_info *ptr)
{
ptr->rtt_rto *= 2; /* next RTO */
if (ptr->rtt_rto > RTT_MAXRTO)
ptr->rtt_rto = RTT_MAXRTO;
if (++ptr->rtt_nrexmt > ptr->rtt_retry)
return(-1); /* time to give up for this packet */
return(0);
}
/* end rtt_timeout */
/*
* Print debugging information on stderr, if the "rtt_d_flag" is nonzero.
*/
void
rtt_debug(struct rtt_info *ptr)
{
if (rtt_d_flag == 0)
return;
fprintf(stderr, "\e[31mrtt = %.3f, srtt = %.3f, rttvar = %.3f, rto = %.3f\n\e[m",
ptr->rtt_rtt, ptr->rtt_srtt, ptr->rtt_rttvar, ptr->rtt_rto);
fflush(stderr);
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。