GFNetworkReconnectPolicy¶
API Reference / Network / 类索引
- 路径:
addons/gf/extensions/network/session/gf_network_reconnect_policy.gd - 模块:
Network - 继承:
RefCounted - API:
public - 类别:运行时句柄 (
runtime_handle) - 首次版本:
3.17.0
通用重连退避策略。 记录重连尝试次数,并按预设延迟序列返回下一次等待时间。它不依赖具体网络后端。
成员概览¶
| 类型 | 名称 | 签名 |
|---|---|---|
| 属性 | delays_msec |
var delays_msec: Array[int] = [500, 1000, 2000, 5000] |
| 属性 | max_attempts |
var max_attempts: int = 0 |
| 属性 | jitter_ratio |
var jitter_ratio: float = 0.0: |
| 方法 | reset |
func reset() -> void: |
| 方法 | has_attempts_remaining |
func has_attempts_remaining() -> bool: |
| 方法 | get_next_delay_msec |
func get_next_delay_msec() -> int: |
| 方法 | record_success |
func record_success() -> void: |
| 方法 | get_attempt_count |
func get_attempt_count() -> int: |
属性¶
delays_msec¶
- API:
public
重连延迟序列,单位毫秒。
结构:
delays_msec: Array[int],按尝试次数索引的重连延迟毫秒数。
max_attempts¶
- API:
public
最大尝试次数。小于等于 0 表示无限尝试。
jitter_ratio¶
- API:
public
抖动比例。0 表示不抖动,0.2 表示在 ±20% 内随机偏移。
方法¶
reset¶
- API:
public
重置尝试计数。
has_attempts_remaining¶
- API:
public
检查是否还允许继续尝试。
返回:允许返回 true。
get_next_delay_msec¶
- API:
public
记录一次失败并返回下一次等待时长。
返回:下一次等待时长;没有尝试空间时返回 -1。
record_success¶
- API:
public
记录一次成功并清空尝试计数。
get_attempt_count¶
- API:
public
获取已经消费的失败尝试次数。
返回:尝试次数。