op_ev_code()
摘要
获取与指定事件关联的数字代码。
语法
op_ev_code (evhandle)
| 参数 | 类型 | 说明 |
|---|---|---|
evhandle |
Evhandle |
标识该事件的事件句柄 [事件句柄可以从本包中的多个内核过程获取——例如 op_ev_current()、op_ev_seek_time() 和 op_ev_next()——以及 op_intrpt_schedule_self() 等其他内核过程。] |
返回类型
int
与指定事件关联的数字代码。如果发生可恢复错误,将返回常量 OPC_EV_CODE_INVALID。
[该值是一个整数,其含义由用户在请求远程、自或组播中断时定义。通常它用于标识中断的用途。]
示例
/* 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);
}
详情
只有当该内核过程应用于带有关联代码的事件时,才保证返回有效结果。支持代码的三种中断类型是自中断、远程中断和组播中断。
用途
提供了一种确定与事件关联的用户定义数字代码的机制,以便识别事件的用途。当一个进程有多个同类型但用途不同的事件处于挂起状态时,就需要这样做。一个例子是由自中断界定的多个超时时间。
错误
- 程序中止:段错误。(由于格式错误的事件句柄)
- 可恢复错误:事件句柄指向的事件无效或当前未被计划。
参考
- 使用内核过程 op_ev_valid() 判断 Evhandle 是否有效
- 使用内核过程 op_ev_type() 确定事件的类型
- 使用内核过程 op_ev_stat() 确定当前统计量中断的输入统计量索引
- 使用内核过程 op_ev_strm() 确定当前流中断的数据流索引
- 使用内核过程 op_ev_time() 确定事件的计划时间
- 使用内核过程 op_ev_ici() 获取与事件关联的 ICI