void main_loop_wait(int timeout) { fd_set rfds, wfds, xfds; int ret, nfds; struct timeval tv; qemu_bh_update_timeout(&timeout); os_host_main_loop_wait(&timeout); tv.tv_sec = timeout / 1000; tv.tv_usec = (timeout % 1000) * 1000; /* poll any events */ /* XXX: separate device handlers from system ones */ nfds = -1; FD_ZERO(&rfds); FD_ZERO(&wfds); FD_ZERO(&xfds); qemu_iohandler_fill(&nfds, &rfds, &wfds, &xfds); if (slirp_is_inited()) { slirp_select_fill(&nfds, &rfds, &wfds, &xfds); } qemu_mutex_unlock_iothread(); ret = select(nfds + 1, &rfds, &wfds, &xfds, &tv); qemu_mutex_lock_iothread(); qemu_iohandler_poll(&rfds, &wfds, &xfds, ret); if (slirp_is_inited()) { if (ret < 0) { FD_ZERO(&rfds); FD_ZERO(&wfds); FD_ZERO(&xfds); } slirp_select_poll(&rfds, &wfds, &xfds); } charpipe_poll(); qemu_clock_run_all_timers(); qemu_run_alarm_timer(); /* Check bottom-halves last in case any of the earlier events triggered them. */ qemu_bh_poll(); }
int wait_loop(HANDLE daemon_handle) { HANDLE wait_list[1]; ULONG status; co_rc_t rc; int ret; fd_set rfds, wfds, xfds; int nfds; struct timeval tv; co_win32_overlapped_init(&daemon_overlapped, daemon_handle); wait_list[0] = daemon_overlapped.read_event; co_win32_overlapped_read_async(&daemon_overlapped); while (1) { status = WaitForMultipleObjects(1, wait_list, FALSE, 1); switch (status) { case WAIT_OBJECT_0: { /* daemon */ profile_me("from daemon"); rc = co_win32_overlapped_read_completed(&daemon_overlapped); if (!CO_OK(rc)) return 0; break; } default: break; } nfds = -1; FD_ZERO(&rfds); FD_ZERO(&wfds); FD_ZERO(&xfds); slirp_select_fill(&nfds, &rfds, &wfds, &xfds); tv.tv_sec = 0; tv.tv_usec = 1000; ret = select(nfds + 1, &rfds, &wfds, &xfds, &tv); if (ret >= 0) { slirp_select_poll(&rfds, &wfds, &xfds); } } return 0; }
static void *slirp_receive_func(void *arg) { slirp_thread_active = 1; while (slirp_thread_active) { // Wait for packets to arrive fd_set rfds, wfds, xfds; int nfds; int ret, timeout; // ... in the output queue nfds = -1; FD_ZERO(&rfds); FD_ZERO(&wfds); FD_ZERO(&xfds); uae_sem_wait (&slirp_sem2); timeout = slirp_select_fill(&nfds, &rfds, &wfds, &xfds); uae_sem_post (&slirp_sem2); if (nfds < 0) { /* Windows does not honour the timeout if there is not descriptor to wait for */ sleep_millis (timeout / 1000); ret = 0; } else { struct timeval tv; tv.tv_sec = 0; tv.tv_usec = timeout; ret = select(0, &rfds, &wfds, &xfds, &tv); if (ret == SOCKET_ERROR) { write_log(_T("SLIRP socket ERR=%d\n"), WSAGetLastError()); } } if (ret >= 0) { uae_sem_wait (&slirp_sem2); slirp_select_poll(&rfds, &wfds, &xfds); uae_sem_post (&slirp_sem2); } } slirp_thread_active = -1; return 0; }
static unsigned int WINAPI slirp_receive_func(void *arg) { D(bug("slirp_receive_func\n")); thread_active_2 = true; while (thread_active) { // Wait for packets to arrive fd_set rfds, wfds, xfds; int nfds, ret, timeout; // ... in the output queue nfds = -1; FD_ZERO(&rfds); FD_ZERO(&wfds); FD_ZERO(&xfds); timeout = slirp_select_fill(&nfds, &rfds, &wfds, &xfds); #if ! USE_SLIRP_TIMEOUT timeout = 10000; #endif if (nfds < 0) { /* Windows does not honour the timeout if there is not descriptor to wait for */ Delay_usec(timeout); ret = 0; } else { struct timeval tv; tv.tv_sec = 0; tv.tv_usec = timeout; ret = select(0, &rfds, &wfds, &xfds, &tv); } if (ret >= 0) slirp_select_poll(&rfds, &wfds, &xfds); } D(bug("slirp_receive_func exit\n")); thread_active_2 = false; return 0; }