op_ev_valid()
摘要
判断事件句柄是否有效(指向一个存在的事件)。
语法
op_ev_valid (evhandle)
| 参数 | 类型 | 说明 |
|---|---|---|
evhandle |
Evhandle |
可能标识某个事件的事件句柄 [事件句柄可以从本包中的多个内核过程获取,例如 op_ev_current()、op_ev_seek_time() 和 op_ev_next(),以及 op_intrpt_schedule_self() 等其他内核过程。] |
返回类型
Boolean
指示指定事件句柄有效或无效的 Boolean 值。
如果某个 Evhandle 被设置为无效状态,以指示某个返回 Evhandle 的内核过程中发生错误;或者它指向一个已经完成或已被撤销的事件;或者它是一个初始化不当的用户变量,则该 Evhandle 无效,本内核过程返回 OPC_FALSE。
示例
/* Obtain the currently executing event (it must be at this module, */
/* since this module woke up.) and the one after it. */
this_event = op_ev_current ();
next_event = op_ev_next_local (this_event);
/* Loop through all of the events scheduled for this module */
/* and cancel any that are retransmission timers. */
while (op_ev_valid (next_event))
{
if ((op_ev_type (next_event) == OPC_INTRPT_SELF) &&
(op_ev_code (next_event) == RETRANS_TIMER))
{
retrans_timer = next_event;
next_event = op_ev_next_local (retrans_timer);
op_ev_cancel (retrans_timer);
}
else
/* Obtain the next event; if there are no more events, op_ev_next_local () */
/* will return an invalid event handle and the loop will terminate. */
next_event = op_ev_next_local (next_event);
}
详情
指向当前正在执行或计划发生的事件的 Evhandle 是有效的。陈旧(stale)的 Evhandle,即指向已经发生的事件的 Evhandle,是无效的。空的(empty)Evhandle,即当不存在此类事件时由 op_ev_next() 等内核过程返回的 Evhandle,也是无效的。
用途
提供了一种在将 Evhandle 用作事件包内核过程的参数之前判断其是否有效的机制。在查找特定事件或某类事件时,使用该内核过程能够为通过 op_ev_next() 等内核过程遍历事件时何时停止循环提供良好的指示。此外,该内核过程还可用于检验某些内核过程返回时是否成功,因为大多数返回事件句柄的内核过程会在失败时设置空的事件句柄。
错误
- 程序中止:段错误。(由于格式错误的事件句柄)
参考
- 使用内核过程 op_ev_type() 确定事件的类型
- 使用内核过程 op_ev_time() 确定事件的时间
- 使用内核过程 op_ev_pending() 判断事件是否处于挂起状态