static int
gettime(struct event_base *base, struct timeval *tp)
{
if (base->tv_cache.tv_sec) {//如果有时间缓存则将缓存赋值给tp
*tp = base->tv_cache;
return (0);
}
#if defined(HAVE_CLOCK_GETTIME) && defined(CLOCK_MONOTONIC)
if (use_monotonic) {//无缓存则使用系统调用获得当前时间
struct timespec ts;
if (clock_gettime(CLOCK_MONOTONIC, &ts) == -1)
return (-1);
tp->tv_sec = ts.tv_sec;
tp->tv_usec = ts.tv_nsec / 1000;
return (0);
}
#endif
return (evutil_gettimeofday(tp, NULL));
}
[libevent]gettime()
最新推荐文章于 2022-12-26 09:49:42 发布