コード例 #1
0
ファイル: socket.c プロジェクト: kvirund/mmc
int	main_loop_iteration(void) {
    HANDLE  hlist[NSOCK];
    int	    i,j;
    DWORD   r,delay;
    ltime_t tm;

    flush_socks();
    window_flush();
    for (i=0,j=0;j<NSOCK;j++)
	if (sockets[j].inuse && sockets[j].event)
	    hlist[i++]=sockets[j].event;
    tm=nearest_timeout();
    if (tm<0)
	delay=INFINITE;
    else if (tm<0x7fffffff)
	delay=(DWORD)tm;
    else
	delay=0x7fffffff;
    r=MsgWaitForMultipleObjects(i,hlist,FALSE,delay,QS_ALLINPUT);
    if (r<0) {
	clerr("MsgWaitForMultipleObjectsEx() failed");
	return -1;
    }
    if (r==WAIT_OBJECT_0+i)
	out_process_input();
    else if (r>=WAIT_OBJECT_0 && r<WAIT_OBJECT_0+i) {
	r-=WAIT_OBJECT_0;
	for (j=0;j<NSOCK;j++)
	    if (sockets[j].event==hlist[r])
		soproc(j,NULL,0);
    }
    process_timeouts();
    return 0;
}
コード例 #2
0
ファイル: socket.c プロジェクト: kvirund/mmc
int	main_loop_iteration(void) {
    fd_set	    rfd,wfd;
    struct timeval  delay;
    int		    i,j,r;
    ltime_t	    tm;
    static int	    siginit=0;

    if (!siginit) {
      signal(SIGCHLD,sigchld);
      signal(SIGINT,fatalsig);
      signal(SIGTERM,fatalsig);
      signal(SIGHUP,fatalsig);
      signal(SIGQUIT,fatalsig);
      siginit=1;
    }
    flush_socks();
    window_flush();
    FD_ZERO(&rfd);
    FD_ZERO(&wfd);
    FD_SET(0,&rfd);
    for (j=i=0;j<NSOCK;j++)
	if (sockets[j].inuse) {
	    if (i<sockets[j].sock)
	      i=sockets[j].sock;
	    FD_SET(sockets[j].sock,&rfd);
	    if (sockets[j].mode==SM_CONN)
	      FD_SET(sockets[j].sock,&wfd);
	}
    tm=nearest_timeout();
    if (tm<0)
	r=select(i+1,&rfd,&wfd,NULL,NULL);
    else {
	delay.tv_usec=(tm%1000)*1000;
	delay.tv_sec=tm/1000;
	r=select(i+1,&rfd,&wfd,NULL,&delay);
    }
    if (r<0) {
	if (errno!=EINTR) {
	    clerr("select() failed");
	    return -1;
	}
    }
    out_sigcheck(); /* just in case that was SIGWINCH */
    if (r>0) {
	if (FD_ISSET(0,&rfd))
	    out_process_input();
	for (j=0;j<NSOCK;j++)
	    if (sockets[j].inuse && (FD_ISSET(sockets[j].sock,&rfd) || FD_ISSET(sockets[j].sock,&wfd)))
		    soproc(j,NULL,0);
    }
    process_timeouts();
    return 0;
}
コード例 #3
0
ファイル: ares_process.c プロジェクト: 002301/node
/*
 * generic process function
 */
static void processfds(ares_channel channel,
                       fd_set *read_fds, ares_socket_t read_fd,
                       fd_set *write_fds, ares_socket_t write_fd)
{
  struct timeval now = ares__tvnow();

  write_tcp_data(channel, write_fds, write_fd, &now);
  read_tcp_data(channel, read_fds, read_fd, &now);
  read_udp_packets(channel, read_fds, read_fd, &now);
  process_timeouts(channel, &now);
  process_broken_connections(channel, &now);
}
コード例 #4
0
ファイル: ares_process.c プロジェクト: Yoko2012/resiprocate
/* Something interesting happened on the wire, or there was a timeout.
 * See what's up and respond accordingly.
 */
void ares_process(ares_channel channel, fd_set *read_fds, fd_set *write_fds)
{
  time_t now;

  time(&now);
  write_tcp_data(channel, write_fds, now);
  read_tcp_data(channel, -1, read_fds, now);
  read_udp_packets(channel, -1, read_fds, now);
  process_timeouts(channel, now);

  /* See if our local pseudo-db has any results. */
  /* Querying this only on timeouts is OK (is not high-performance) */
  ares_local_process_requests();
}
コード例 #5
0
ファイル: ares_process.c プロジェクト: Yoko2012/resiprocate
/* Something happened on wire or there was a timeout. This interface
 * is called for poll()-like systems.
 */
void ares_process_poll(ares_channel channel, int server_idx,
	int rdFd, int wrFd, time_t now) {
  if ( server_idx!= -1 ) {
      assert( rdFd!=-1 || wrFd!=-1 );	// at least one active
      if ( wrFd!=-1 && channel->servers[server_idx].tcp_socket==wrFd ) {
          write_tcp_data_core(channel, server_idx, now);
      }
      // writes can only be for TCP (we don't ask for UDP writable events)
      if ( rdFd!=-1 && channel->servers[server_idx].tcp_socket == rdFd )
              read_tcp_data(channel, server_idx, NULL, now);
      if ( rdFd!=-1 && channel->servers[server_idx].udp_socket == rdFd )
              read_udp_packets(channel, server_idx, NULL, now);
  } else {
      process_timeouts(channel, now);
      ares_local_process_requests();
  }
}
コード例 #6
0
ファイル: dbus.c プロジェクト: etix/vlc
static void *Run( void *data )
{
    intf_thread_t *p_intf = data;
    intf_sys_t    *p_sys = p_intf->p_sys;

    int canc = vlc_savecancel();

    for( ;; )
    {
        vlc_mutex_lock( &p_sys->lock );

        int i_watches = vlc_array_count( p_sys->p_watches );
        struct pollfd fds[i_watches];
        memset(fds, 0, sizeof fds);

        int i_fds = GetPollFds( p_intf, fds );
        int timeout = next_timeout(p_intf);

        vlc_mutex_unlock( &p_sys->lock );

        /* thread cancellation is allowed while the main loop sleeps */
        vlc_restorecancel( canc );

        while (poll(fds, i_fds, timeout) == -1)
        {
            if (errno != EINTR)
                goto error;
        }

        canc = vlc_savecancel();

        /* Was the main loop woken up manually ? */
        if (fds[0].revents & POLLIN)
        {
            char buf;
            (void)read( fds[0].fd, &buf, 1 );
        }

        /* We need to lock the mutex while building lists of events,
         * timeouts and watches to process but we can't keep the lock while
         * processing them, or else we risk a deadlock:
         *
         * The signal functions could lock mutex X while p_events is locked;
         * While some other function in vlc (playlist) might lock mutex X
         * and then set a variable which would call AllCallback(), which itself
         * needs to lock p_events to add a new event.
         */
        vlc_mutex_lock( &p_intf->p_sys->lock );

        process_timeouts(p_intf);

        /* Get the list of watches to process */
        i_watches = vlc_array_count( p_sys->p_watches );
        DBusWatch *p_watches[i_watches ? i_watches : 1];
        for( int i = 0; i < i_watches; i++ )
        {
            p_watches[i] = vlc_array_item_at_index( p_sys->p_watches, i );
        }

        /* Get the list of events to process */
        int i_events = vlc_array_count( p_intf->p_sys->p_events );
        callback_info_t* p_info[i_events ? i_events : 1];
        for( int i = i_events - 1; i >= 0; i-- )
        {
            p_info[i] = vlc_array_item_at_index( p_intf->p_sys->p_events, i );
            vlc_array_remove( p_intf->p_sys->p_events, i );
        }

        /* now we can release the lock and process what's pending */
        vlc_mutex_unlock( &p_intf->p_sys->lock );

        ProcessEvents( p_intf, p_info, i_events );
        ProcessWatches( p_intf, p_watches, i_watches, fds, i_fds );

        DispatchDBusMessages( p_intf );
    }
error:
    vlc_restorecancel(canc);
    return NULL;
}