timer.tcl

来自「可以在ns-2中进行仿真的SPIN路由协议的源码」· TCL 代码 · 共 47 行

TCL
47
字号
## A simple NewTimer class.  You can derive a subclass of NewTimer# to provide a simple mechanism for scheduling events:## 	$self sched $delay -- causes "$self timeout" to be called#				$delay seconds in the future#	$self cancel	   -- cancels any pending scheduled callback# Class NewTimer# sched is the same as resched; the previous setting is cancelled# and another event is scheduled. No state is kept for the NewTimers.# This is different than the C++ NewTimer API in NewTimer-handler.cc,h; where a # sched aborts if the NewTimer is already set. C++ NewTimers maintain state # (e.g. IDLE, PENDING..etc) that is checked before the NewTimer is scheduled.NewTimer instproc sched delay {    global ns_    $self instvar id_    $self cancel    set now [$ns_ now]    set id_ [$ns_ at [expr $now + $delay] "$self timeout"]}NewTimer instproc destroy {} {	$self cancel}NewTimer instproc cancel {} {	global ns_	$self instvar id_	if [info exists id_] {		$ns_ cancel $id_		unset id_	}}# resched and expire are added to have a similar API to C++ NewTimers.NewTimer instproc resched delay {	$self sched $delay }# the subclass must provide the timeout functionNewTimer instproc expire {} {	$self timeout}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?