예제 #1
0
static VMIOS_INTERCEPT_FN(netPoll)
{
    u_int timeMS;
    getArg(processor, object, 0, &timeMS);

    if(DIAG_HIGH) {
        vmiMessage("I", PREFIX, "netPoll #" FMT_64d " at %d ***********", object->pollCount, timeMS);
    }

    object->pollCount++;

    int nfds = -1;

    Slirp *slirp = object->slirp;

    FD_ZERO(&slirp->rfds);
    FD_ZERO(&slirp->wfds);
    FD_ZERO(&slirp->xfds);

    slirp_select_fill(slirp, &nfds, &slirp->rfds, &slirp->wfds, &slirp->xfds);

    struct timeval tv;
    tv.tv_sec = 0;
    tv.tv_usec = 0;

    int r = recSelectSocket(nfds + 1, &slirp->rfds, &slirp->wfds, &slirp->xfds, &tv);
    slirp_select_poll(slirp, &slirp->rfds, &slirp->wfds, &slirp->xfds, timeMS, r >= 0);
}
예제 #2
0
int main_loop_wait(int nonblocking)
{
    int ret;
    uint32_t timeout = UINT32_MAX;

    if (nonblocking) {
        timeout = 0;
    }

    /* poll any events */
    /* XXX: separate device handlers from system ones */
    nfds = -1;
    FD_ZERO(&rfds);
    FD_ZERO(&wfds);
    FD_ZERO(&xfds);

#ifdef CONFIG_SLIRP
    slirp_update_timeout(&timeout);
    slirp_select_fill(&nfds, &rfds, &wfds, &xfds);
#endif
    qemu_iohandler_fill(&nfds, &rfds, &wfds, &xfds);
    ret = os_host_main_loop_wait(timeout);
    qemu_iohandler_poll(&rfds, &wfds, &xfds, ret);
#ifdef CONFIG_SLIRP
    slirp_select_poll(&rfds, &wfds, &xfds, (ret < 0));
#endif

    qemu_run_all_timers();

    return ret;
}
예제 #3
0
//This function is to be periodically called
//to keep the internal packet state flowing.
static void slirp_tick(void)
{
    int ret2,nfds;
    struct timeval tv;
    fd_set rfds, wfds, xfds;
    int timeout;
    nfds=-1;
    
    if (slirp_inited)
    {
        FD_ZERO(&rfds);
        FD_ZERO(&wfds);
        FD_ZERO(&xfds);
        timeout=slirp_select_fill(&nfds,&rfds,&wfds,&xfds); //this can crash
        
        if(timeout<0)
            timeout=500;
        tv.tv_sec=0;
        tv.tv_usec = timeout;    //basilisk default 10000
        
        ret2 = select(nfds + 1, &rfds, &wfds, &xfds, &tv);
        if(ret2>=0){
            SDL_LockMutex(slirp_mutex);
            slirp_select_poll(&rfds, &wfds, &xfds);
            SDL_UnlockMutex(slirp_mutex);
        }
    }
}
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();

}
예제 #5
0
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;
}
예제 #6
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;
}
예제 #7
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;
}