Пример #1
0
/*
 * set and clear entries in the select array ..
 */
static void
select_update_selectfds(rb_fde_t *F, short event, PF * handler)
{
	/* Update the read / write set */
	if (event & RB_SELECT_READ) {
		if (handler) {
			MY_FD_SET(F->fd, &select_readfds);
			F->pflags |= RB_SELECT_READ;
		} else {
			MY_FD_CLR(F->fd, &select_readfds);
			F->pflags &= ~RB_SELECT_READ;
		}
	}
	if (event & RB_SELECT_WRITE) {
		if (handler) {
			MY_FD_SET(F->fd, &select_writefds);
			F->pflags |= RB_SELECT_WRITE;
		} else {
			MY_FD_CLR(F->fd, &select_writefds);
			F->pflags &= ~RB_SELECT_WRITE;
		}
	}
	if (F->pflags & (RB_SELECT_READ | RB_SELECT_WRITE)) {
		if (F->fd > rb_maxfd)
			rb_maxfd = F->fd;
	} else if (F->fd <= rb_maxfd) {
		while (rb_maxfd >= 0 && !FD_ISSET(rb_maxfd, &select_readfds)
		       && !FD_ISSET(rb_maxfd, &select_writefds))
			rb_maxfd--;
	}
}
Пример #2
0
void
Selector::delete_fd( int fd, IO_FUNC interest )
{
#if !defined(WIN32)
	if ( fd < 0 || fd >= fd_select_size() ) {
		EXCEPT( "Selector::delete_fd(): fd %d outside valid range 0-%d",
				fd, _fd_select_size-1 );
	}
#endif

	m_single_shot = SINGLE_SHOT_SKIP;

	if (IsDebugLevel(D_DAEMONCORE)) {
		dprintf(D_DAEMONCORE | D_VERBOSE, "selector %p deleting fd %d\n", this, fd);
	}

	switch( interest ) {

	  case IO_READ:
		MY_FD_CLR( fd, save_read_fds );
		break;

	  case IO_WRITE:
		MY_FD_CLR( fd, save_write_fds );
		break;

	  case IO_EXCEPT:
		MY_FD_CLR( fd, save_except_fds );
		break;

	}
}
Пример #3
0
void io_sig_handler(int num)
{
    fd_set	rfds;
    int	conn_id, ret, selret, count;
	struct timeval	timeout;

	if(num){}
	do
	{
		timeout.tv_sec = 0;		/* Don't wait, just poll */
		timeout.tv_usec = 0;
		list_to_fds( &rfds );
#ifdef __linux__
		selret = poll(Pollfds, Pollfd_size, 0);
#else
		selret = select(FD_SETSIZE, &rfds, NULL, NULL, &timeout);
#endif
		if(selret > 0)
		{
			conn_id = 0;
			while( (ret = fds_get_entry( &rfds, &conn_id )) > 0 ) 
			{
				if( Net_conns[conn_id].reading )
				{
					count = 0;
					do
					{
						if(Net_conns[conn_id].channel)
						{
							do_read( conn_id );
							count = get_bytes_to_read(conn_id);
						}
						else
						{
							count = 0;
						}
					}while(count > 0 );
				}
				else
				{
					do_accept( conn_id );
				}
				MY_FD_CLR( (unsigned)Net_conns[conn_id].channel, &rfds );
	    	}
		}
	}while(selret > 0);
}
Пример #4
0
void
SelectSetRemove(SelectSetPtr const ssp, const int fd)
{
#if defined(__DECC) || defined(__DECCXX)
#pragma message save
#pragma message disable trunclongint
#endif
    if ((fd >= 0) && (MY_FD_ISSET(fd, &ssp->fds)))
    {
        MY_FD_CLR(fd, &ssp->fds);
        /* Note that maxfd is left alone, even if maxfd was
         * this one.  That is okay.
         */
        --ssp->numfds;
    }
#if defined(__DECC) || defined(__DECCXX)
#pragma message restore
#endif
}	/* SelectSetRemove */
Пример #5
0
void tcpip_task( void *dummy)
{
	/* wait for an IO signal, find out what is happening and
	 * call the right routine to handle the situation.
	 */
	fd_set	rfds, *pfds;
#ifndef __linux__
	fd_set efds;
#endif
	int	conn_id, ret, count;
#ifndef WIN32
	int data;
#endif
	if(dummy){}
	while(1)
	{
		while(!DIM_IO_valid)
			dim_usleep(1000);

		list_to_fds( &rfds );
		MY_FD_ZERO(&efds);
#ifdef WIN32
		pfds = &efds;
#else
		pfds = &rfds;
#endif
		MY_FD_SET( DIM_IO_path[0], pfds );
#ifdef __linux__
		ret = poll(Pollfds, Pollfd_size, -1);
#else
		ret = select(FD_SETSIZE, &rfds, NULL, &efds, NULL);
#endif
		if(ret <= 0)
		{
		    printf("poll returned %d, errno %d\n", ret, errno);
		}
		if(ret > 0)
		{
			if(MY_FD_ISSET(DIM_IO_path[0], pfds) )
			{
#ifndef WIN32
				read(DIM_IO_path[0], &data, 4);
				DIM_IO_Done = 0;
#endif
				MY_FD_CLR( (unsigned)DIM_IO_path[0], pfds );
			}
/*
			{
			DISABLE_AST
*/
			conn_id = 0;
			while( (ret = fds_get_entry( &rfds, &conn_id )) > 0 ) 
			{
				if( Net_conns[conn_id].reading )
				{
					count = 0;
					do
					{
						DISABLE_AST
						if(Net_conns[conn_id].channel)
						{
							do_read( conn_id );
							count = get_bytes_to_read(conn_id);
						}
						else
						{
							count = 0;
						}
						ENABLE_AST
					}while(count > 0 );
				}
				else
				{
					DISABLE_AST
					do_accept( conn_id );
					ENABLE_AST
				}
				MY_FD_CLR( (unsigned)Net_conns[conn_id].channel, &rfds );
			}
/*
			ENABLE_AST
			}
*/
#ifndef WIN32
			return;
#endif
		}