op_ev_equal()
摘要
比较两个事件句柄是否相等。
语法
op_ev_equal (evhandle_a, evhandle_b)
| 参数 | 类型 | 说明 |
|---|---|---|
evhandle_a |
Evhandle |
事件句柄 [事件句柄可以从本包中的多个内核过程获取,例如 op_ev_current()、op_ev_seek_time() 和 op_ev_next(),以及 op_intrpt_schedule_self() 等其他内核过程。] |
evhandle_b |
Evhandle |
事件句柄 [事件句柄可以从本包中的多个内核过程获取,例如 op_ev_current()、op_ev_seek_time() 和 op_ev_next(),以及 op_intrpt_schedule_self() 等其他内核过程。] |
返回类型
Boolean
指示两个事件句柄是否指向同一事件的布尔值。
若两个事件句柄指向同一事件则返回 OPC_TRUE;若不同或发生可恢复错误则返回 OPC_FALSE。
示例
retrans_event = op_intrpt_schedule_self (time, 0)
...
/* if the current event is the retransmit timer, */
/* then retransmit the packet. */
cur_event = op_ev_current ();
if (op_ev_equal (cur_event, retrans_event) == OPC_TRUE)
{
op_pk_send (pkptr, 0);
}
详情
如果两个事件句柄都指向同一事件,则认为它们相等。注意,Evhandle 是数据结构(而非标量变量或指针),不应直接使用 C 语言的 ==(等于)运算符进行比较。
该内核过程在返回结果之前会先测试 Evhandle 的有效性,从而防止将其用于比较指向已取消或其他无效事件的事件句柄。
用途
提供了一种比较两个 Evhandle 是否相等的机制。该内核过程的典型应用是验证当前事件是否为预期事件:当前事件的 Evhandle 可通过 op_ev_current() 获取,然后将其与先前从 op_intrpt_schedule_self() 等内核过程获得的 Evhandle 进行比较。
错误
- 程序中止:段错误。(由于格式错误的事件句柄)
- 可恢复错误:事件句柄指向的事件无效或当前未被计划。
参考
- 使用内核过程 op_ev_valid() 判断 Evhandle 是否有效
- 使用内核过程 op_ev_type() 确定事件的类型
- 使用内核过程 op_ev_time() 确定事件的计划时间
- 使用内核过程 op_ev_pending() 判断事件是否挂起