Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix redeliver Timer error #358

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

GithubGaoYang
Copy link

修复重新发送计时器错误

错误描述

在 Re-delivery frame 时,对 frame 的 timestamp 进行了重新赋值,但程序运行需要消耗时间,导致会出现几毫秒的误差,于是在定时器下一次被触发时,nowTimestamp - frame.timestamp 比 (retryTimeInterval/1000.0) 小几毫秒,导致多数情况下定时器每执行两次才会触发一次 Re-delivery frame 逻辑,误差测试如下:
image

修复方案

为 Frame 增加一个重试次数(retryCount)变量,在 redeliver 方法中,比较 时间差值(nowTimestamp - frame.timestamp) 与 重试时间*重试次数((retryTimeInterval/1000.0) * frame.retryCount)的大小,即:

if (nowTimestamp - frame.timestamp) >= (retryTimeInterval/1000.0) * Double(frame.retryCount) {}

说明

以上是我能想到的处理方案,如果有更好的处理方式,欢迎回复我。


var duplicatedFrame = frame
duplicatedFrame.frame.dup = true
duplicatedFrame.timestamp = nowTimestamp
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't believe we should remove the this part:

duplicatedFrame.timestamp = nowTimestamp

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants