我使用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')