op_ev_cancel()

摘要

撤销先前已计划的事件。

语法

op_ev_cancel (evhandle)
参数 类型 说明
evhandle Evhandle 标识待取消事件的事件句柄
事件句柄可以从本包中的多个内核过程获取,例如 op_ev_seek_time() 和 op_ev_next(),以及 op_intrpt_schedule_self() 等其他内核过程。

返回类型

Compcode

若操作成功完成则返回 OPC_COMPCODE_SUCCESS;否则返回 OPC_COMPCODE_FAILURE。

示例

/* 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_cancel() 取消事件,比让事件递送到目的地后再忽略它们更为高效。

用途

提供了一种撤销不再必要或不再需要的事件的机制。该内核过程的一种常见用途是撤销由通过 op_intrpt_schedule_self() 安排的中断所表示的超时。如果确认数据包到达或其他中断在超时时间到期之前发生,通常通过该内核过程取消该超时,并可能通过重新安排将其恢复为原来的时长。

错误

  • 程序中止:段错误。(由于格式错误的事件句柄)
  • 可恢复错误:事件句柄指向的事件无效或当前未被计划。
  • 可恢复错误:当前事件(<schedule_id>)不能被取消。
  • 可恢复错误:正在执行的事件(<schedule_id>)不能被取消。
  • 可恢复错误:无法取消未定位的事件(<schedule_id>)。

参考

本站文档由 北京智网畅联科技有限公司 整理、翻译并提供 · Documentation compiled and provided by Beijing ZNetLink Technology Co., Ltd.

交流群 · QQ Group:OPNET/智网妙算网络仿真交流群(群号 486383494)

原文档 © 2017 Riverbed Technology · 本站为公益翻译,由 AI 辅助完成,请仔细甄别

Original documentation © 2017 Riverbed Technology. Community translation, AI-assisted. Contact: jiazequn@znetlink.com