0

我在一些超时后使用 libevent 执行一些任务,超时是随机选择的,并且每次都更改。问题是我无法将 timeval 变量设置为随机时间。

int TIMEOUT = 2000000; // 2 millions micro seconds, which is 2 seconds
int mytimeout = (rand() % TIMEOUT) + 1; // a random time between 0 and 2 seconds
int mysec = mytime/1000000; // the number of seconds
int myMicroSec = mytime -  mysec * 1000000; // the number of micro seconds
static struct timeval poll_interval_tv = {mysec, myMicroSec};

myevent = event_new(libevent_get_base(), -1,EV_TIMEOUT,
                        mycallback_function, arg);

它返回这些错误:错误:初始化元素不是常量错误:(接近初始化'poll_interval_tv.tv_sec')

4

0 回答 0