void io (const char *what) { static int first_time = 1; long clock_timeout = 0, timer_timeout = 0, real_timeout = 0; static struct timeval my_now, my_timer, *time_ptr = &my_timer; int hold_over, rc; fd_set rd, wd; get_time(&my_now); now = my_now.tv_sec; /* CHECK FOR CPU SAVER MODE */ if (!cpu_saver && get_int_var(CPU_SAVER_AFTER_VAR)) if (now - idle_time > get_int_var(CPU_SAVER_AFTER_VAR) * 60) cpu_saver_on(0, NULL); rd = readables; wd = writables; FD_ZERO(&wd); FD_ZERO(&rd); set_screens(&rd, &wd); set_server_bits(&rd, &wd); set_process_bits(&rd); set_socket_read(&rd, &wd); icmp_sockets(&rd, &wd); #if defined(WANT_THREAD) #ifdef WANT_NSLOOKUP set_dns_output_fd(&rd); #endif #ifdef WANT_PTEST set_ptest_output_fd(&rd); #endif #ifdef WANT_MP3PLAYER set_mp3_output_fd(&rd); #endif # if defined(GTK) if (tgtk_okay()) tgtk_set_output_fd(&rd); # endif #endif clock_timeout = (timeout_select - (my_now.tv_sec % timeout_select)) * 1000; if (cpu_saver && get_int_var(CPU_SAVER_EVERY_VAR)) clock_timeout += (get_int_var(CPU_SAVER_EVERY_VAR) - 1) * 60000; timer_timeout = TimerTimeout(); if ((hold_over = unhold_windows())) real_timeout = 0; else if (timer_timeout <= clock_timeout) real_timeout = timer_timeout; else real_timeout = clock_timeout; if (real_timeout == -1) time_ptr = NULL; else { time_ptr->tv_sec = real_timeout / 1000; time_ptr->tv_usec = ((real_timeout % 1000) * 1000); } /* GO AHEAD AND WAIT FOR SOME DATA TO COME IN */ switch ((rc = new_select(&rd, &wd, time_ptr))) { case 0: break; case -1: { /* if we just got a sigint */ first_time = 0; if (cntl_c_hit) edit_char('\003'); else if (errno && errno != EINTR) { int ii = 0; fd_set rd1, wd1; char ii_buff_r[500]; char ii_buff_w[500]; int ii_r[FD_SETSIZE]; int ii_w[FD_SETSIZE]; yell("Select failed with [%d:%s]", errno, strerror(errno)); /* Reseed fd_sets so we can dig further */ yell("Packing fd_sets... Dump of fd's set in fd_set"); ii_buff_r[0] = '\0'; ii_buff_w[0] = '\0'; for (ii = 0; ii < FD_SETSIZE; ii++) { ii_r[ii] = 0; ii_w[ii] = 0; } FD_ZERO(&wd1); FD_ZERO(&rd1); set_screens(&rd1, &wd1); set_server_bits(&rd1, &wd1); set_process_bits(&rd1); set_socket_read(&rd1, &wd1); icmp_sockets(&rd1, &wd1); #if defined(WANT_THREAD) #ifdef WANT_NSLOOKUP set_dns_output_fd(&rd1); #endif #ifdef WANT_PTEST set_ptest_output_fd(&rd1); #endif #ifdef WANT_MP3PLAYER set_mp3_output_fd(&rd1); #endif # if defined(GTK) if (tgtk_okay()) tgtk_set_output_fd(&rd1); # endif #endif for (ii = 0; ii <= global_max_fd; ii++) { fd_set rblah, wblah; memcpy(&rblah, &rd1, sizeof(fd_set)); FD_SET(ii, &rblah); if (memcmp(&rblah, &rd1, sizeof(fd_set)) == 0) { char blahblah[20]; sprintf(blahblah, "%d ", ii); strcat(ii_buff_r, blahblah); ii_r[ii] = 1; } memcpy(&wblah, &wd1, sizeof(fd_set)); FD_SET(ii, &wblah); if (memcmp(&wblah, &wd1, sizeof(fd_set)) == 0) { char blahblah[20]; yell("blah"); sprintf(blahblah, "%d ", ii); strcat(ii_buff_w, blahblah); ii_w[ii] = 1; } } yell("Read fd's in set: %s", (ii_buff_r[0] == '\0') ? "<NONE>" : ii_buff_r); for (ii = 0; ii <= global_max_fd; ii++) { if (ii_r[ii] == 1) { struct stat st; if (fstat(ii, &st) == -1) { yell("READ FD %d is causing the select failure!", ii); } else { if (S_ISSOCK(st.st_mode)) yell("READ FD %d is a socket!", ii); else if (S_ISREG(st.st_mode)) yell("READ FD %d is a regular file!", ii); else if (S_ISFIFO(st.st_mode)) yell("READ FD %d is a FIFO!", ii); else ; } } } yell("Write fd's in set: %s", (ii_buff_w[0] == '\0') ? "<NONE>" : ii_buff_w); for (ii = 0; ii <= global_max_fd; ii++) { if (ii_w[ii] == 1) { struct stat st; if (fstat(ii, &st) == -1) { yell("WRITE FD %d is causing the select failure!", ii); } else { if (S_ISSOCK(st.st_mode)) yell("WRITE FD %d is a socket!", ii); else if (S_ISREG(st.st_mode)) yell("WRITE FD %d is a regular file!", ii); else if (S_ISFIFO(st.st_mode)) yell("WRITE FD %d is a FIFO!", ii); else ; } } } sleep(10); } else { #if 0 yell("errno 0 rc = -1, maybe it'll go away"); sleep(10); #endif } break; } /* we got something on one of the descriptors */ default: { cntl_c_hit = 0; now = time(NULL); make_window_current(NULL); do_screens(&rd); check_icmpresult(&rd, &wd); #if defined(WANT_THREAD) #ifdef WANT_NSLOOKUP dns_check(&rd); #endif #ifdef WANT_PTEST ptest_check(&rd); #endif #ifdef WANT_MP3PLAYER mp3_check(&rd); #endif # if defined(GTK) if (tgtk_okay()) tgtk_check(&rd); # endif #endif do_server(&rd, &wd); do_processes(&rd); scan_sockets(&rd, &wd); clean_sockets(); break; } } now = time(NULL); ExecuteTimers(); get_child_exit(-1); if (update_refresh) { update_refresh = 0; refresh_screen(0, NULL); } if (!hold_over) cursor_to_input(); if (update_clock(RESET_TIME)) { if (get_int_var(CLOCK_VAR)) { update_all_status(current_window, NULL, 0); cursor_to_input(); } clean_queue(get_int_var(TRANSFER_TIMEOUT_VAR)); /* timeout if send time is greater than 5 minutes */ } /* (set in term.c) -- we should redraw the screen here */ if (need_redraw) refresh_screen(0, NULL); #ifdef WANT_THREAD if (scan_done) scan_is_done(); #endif alloca(0); return; }
void FREEZE_NET::Epoll::Loop() { epoll_event ev_buf[256]; while (!stopping_) { // Execute any due timers. int timeout = (int) ExecuteTimers(); // Wait for events. int n = epoll_wait(epoll_fd_, &ev_buf[0], 256, timeout ? timeout : -1); if (n == -1 && errno == EINTR) { continue; } assert(n != -1); for (int i = 0; i < n; i++) { poll_entry_t *pe = ((poll_entry_t*) ev_buf[i].data.ptr); if (pe->fd_ == retired_fd) { continue; } if (ev_buf[i].events & (EPOLLERR | EPOLLHUP)) { pe->events_->InEvent(); } if (pe->fd_ == retired_fd) { continue; } if (ev_buf[i].events & EPOLLOUT) { pe->events_->OutEvent(); } if (pe->fd_ == retired_fd) { continue; } if (ev_buf[i].events & EPOLLIN) { pe->events_->InEvent(); } } // Destroy retired event sources. for (retired_t::iterator it = retired_.begin(); it != retired_.end(); ++it) { delete *it; } retired_.clear(); } }