diff options
| author | zy <[email protected]> | 2023-09-13 10:23:23 +0000 |
|---|---|---|
| committer | zy <[email protected]> | 2023-09-13 10:23:23 +0000 |
| commit | 5c859f8726be8fae89df8b08520221dc6f7b6563 (patch) | |
| tree | f10ea1035f6207a3acbef36f463110436f30093a /src/timeout.rs | |
| parent | 37f9a572171a4b3b02fd9140f28481a33863382d (diff) | |
仿照 test-timeout.c 编写 test_timeout.rs
- cfg1 测试不通过, 临时的 now 超过了 100 就 panic
- cfg2b 反而可以测试通过;
修正了 timeout.rs 的几个类型错误, 为一些结构体 提供默认初始化方法.
Diffstat (limited to 'src/timeout.rs')
| -rw-r--r-- | src/timeout.rs | 47 |
1 files changed, 42 insertions, 5 deletions
diff --git a/src/timeout.rs b/src/timeout.rs index b331f1f..297635b 100644 --- a/src/timeout.rs +++ b/src/timeout.rs @@ -52,7 +52,7 @@ pub struct timeout_cb { // #[cfg(TIMEOUT_DISABLE_INTERVALS)] pub const TIMEOUT_INT: u32 = 1; -pub const TIMEOUT_ABS: u32 = 2; +pub const TIMEOUT_ABS: i32 = 2; // TODO 宏定义 TIMEOUT_INITIALIZER timeout_setcb @@ -84,6 +84,27 @@ pub struct timeout { // #[cfg(TIMEOUT_DISABLE_RELATIVE_ACCESS)] pub timeouts: *mut timeouts, /* timeouts collection if member of */ } + +impl Default for timeout { + fn default() -> Self { + timeout { + flags: 0, + expires: 0, + pending: null_mut(), + tqe: timeout_TAILQ_ENTRY { + tqe_next: null_mut(), + tqe_prev: null_mut(), + }, + callback: timeout_cb { + fn_: None, + arg: null_mut(), + }, + interval: 0, + timeouts: null_mut(), + } + } +} + #[link(name = "timeout")] extern "C" { /* initialize timeout structure (same as TIMEOUT_INITIALIZER) */ @@ -136,11 +157,15 @@ extern "C" { // TODO check FILE type pub fn timeouts_check(arg1: *mut timeouts, arg2: *mut FILE) -> bool; } +extern "C" { + pub static mut stderr: *mut FILE; +} + -pub const TIMEOUTS_PENDING: u32 = 16; -pub const TIMEOUTS_EXPIRED: u32 = 32; -pub const TIMEOUTS_ALL: u32 = 48; -pub const TIMEOUTS_CLEAR: u32 = 64; +pub const TIMEOUTS_PENDING: i32 = 16; +pub const TIMEOUTS_EXPIRED: i32 = 32; +pub const TIMEOUTS_ALL: i32 = 48; +pub const TIMEOUTS_CLEAR: i32 = 64; // 原为 C 的宏定义 能转为 C 兼容函数 #[no_mangle] @@ -172,6 +197,18 @@ pub struct timeouts_it { pub to: *mut timeout, } +impl Default for timeouts_it { + fn default() -> Self { + timeouts_it { + flags: 0, + pc: 0, + i: 0, + j: 0, + to: null_mut(), + } + } +} + /* return next timeout in pending wheel or expired queue. caller can delete * the returned timeout, but should not otherwise manipulate the timing * wheel. in particular, caller SHOULD NOT delete any other timeout as that |
