void operator()(const Event& event) { _process_event(event); }
/* ******************* local function impe*************** */ static void *_watch_task(void* args) { fd_set rfds; struct timeval timeout; watch_entry_t *pentry; int i = 0, max_fd = 0, ret; dbg("task start\n"); while( g_watch_data.task_runflag ) { /* set timeout value */ timeout.tv_sec = 1; timeout.tv_usec = 0; /* add fds */ FD_ZERO(&rfds); for(i=0, max_fd=0, pentry = g_watch_data.entry; \ i < g_watch_data.max_instance; \ i++, pentry++) { if( -1 != pentry->fd ) { FD_SET(pentry->fd, &rfds); if( pentry->fd > max_fd ) max_fd = pentry->fd; } } if( 0 == max_fd ) { usleep(50*1000); dbg("no watched\n"); continue; } //dbg("watched %d\n", max_fd); /* do select */ ret = select(max_fd + 1, &rfds, NULL, NULL, &timeout); //dbg("select ret=%d\n", ret); if( -1 == ret ) { perror("select()"); }else if( ret ){ /* find which fd can be read */ for( i=0, pentry=g_watch_data.entry; \ i<g_watch_data.max_instance; \ i++, pentry++) { if( (-1 != pentry->fd) && FD_ISSET(pentry->fd, &rfds) ) { /* read the event, the find it & process */ _process_event(pentry); break; } } } } dbg("task exit\n"); g_watch_data.task_runflag = 2; return NULL; }