[問題] run_timer的用法
第一次接觸用linux編譯的C
想請問一下
開發平台(Platform): (Ex: VC++, GCC, Linux, ...)
Linux
問題(Question):
想要實現每隔3秒將用run_timer將一個整數值固定增加並
儲存到 _channel裡使得
lp->set_channel(_channel);
可以每3秒重新設定一次
我將
void WINGLinkStat::run_timer(Timer *) {
clear_stale();
send_probe();
int _channel;
int k=1;
_channel = 2400+ 5*k;
k++;
_timer.reschedule_after_msec(3000);
}
void WINGLinkStat::send_probe() {
wing_probe *lp = (struct wing_probe *) (p->data() + sizeof(click_ether));
lp->set_channel(_dev->channel());
}
請問這樣的寫法錯在哪? _timer 每3秒重新schedule一次使得k每3秒增加
另外_channel的值這樣能確實增加嗎?
程式碼(Code):(請善用置底文網頁, 記得排版)
摘錄處
http://codepad.org/lDXe7LxN
完整原始碼
http://codepad.org/xA4H4hx0
補充說明(Supplement):
因為我在send_probe直接改用sleep好像會使程式的值無法固定住。
所以想要用timer的方法,還是有辦法能直接改呢?
希望大家能指正我錯誤在哪 感謝各位!
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.113.62.210
C_and_CPP 近期熱門文章
PTT數位生活區 即時熱門文章