以下是对epoll的封装。注意:封装后的epoll_wait前3个参数与原来一致,只是没有了第4个超时参数,将根据时间链表设置超时参数。
int tepoll_wait( int epollfd, epoll_event *events, int max_event_number )
{
struct timeval now;
struct timeval tv;
struct timeval *tvp;
tevent_t *tp;
int n;
for ( ;; )
{
if ( gettimeofday( &now, NULL ) < 0 )
error( 1, errno, "tselect: gettimeofday failure" );
//若时间链表中有超时事件,则取出第一个超时时间
if ( active )
{
tv.tv_sec = active->tv.tv_sec - now.tv_sec;;
tv.tv_usec = active->tv.tv_usec - now.tv_usec;
if ( tv.tv_usec < 0 )
{
tv.tv_usec += 1000000;
tv.tv_sec--;
}
tvp = &tv;
}
else
tvp = NULL;
if(tvp == NULL)
n = epoll_wait( epollfd, e