int loop_start (evLoop *loop, int type){ while (loop->active_handles){ /* closing handles */ loop_run_closing_handles(loop); loop_update_time(loop); int timeout; timeout = next_timeout(loop); if (type == 1 && timeout > 1){ timeout = 1; } loop_run_timers(loop); loop_run_immediate(loop); if (QUEUE_EMPTY(&loop->io_queue)) { #ifdef _WIN32 Sleep(timeout); #else usleep(1000 * timeout); #endif } else { io_poll(loop, timeout); } /* run once */ if (type == 1){ loop_update_time(loop); loop_run_timers(loop); break; } } /* check closing handles one last time*/ loop_run_closing_handles(loop); return loop->active_handles > 0; }
int loop_start (evLoop *loop, int type){ while (loop->active_handles){ /* closing handles */ QUEUE *q; evHandle *handle; while ( !QUEUE_EMPTY(&loop->closing_queue) ){ q = QUEUE_HEAD(&(loop)->closing_queue); QUEUE_REMOVE(q); handle = QUEUE_DATA(q, evHandle, queue); assert(handle); if (handle->close != NULL){ handle->close(handle); } _free_handle(handle); } loop_update_time(loop); int timeout; if (type == 1){ timeout = 0; } else { timeout = next_timeout(loop); } loop_run_timers(loop); loop_run_immediate(loop); if (QUEUE_EMPTY(&loop->io_queue)) { #ifdef _WIN32 Sleep(timeout); #else usleep(1000 * timeout); #endif } else { io_poll(loop, timeout); } /* run once */ if (type == 1){ break; } } return loop->active_handles > 0; }