Exemple #1
0
static int do_read( int conn_id )
{
	/* There is 'data' pending, read it.
	 */
	int	len, totlen, size, count;
	char	*p;

	count = get_bytes_to_read(conn_id);
	if(!count)
	{
/*
		dna_report_error(conn_id, -1,
			"Connection closed by remote peer", DIM_ERROR, DIMTCPRDERR);
		printf("conn_id %d\n", conn_id);
*/
		Net_conns[conn_id].read_rout( conn_id, -1, 0 );
		return 0;
	}

	size = Net_conns[conn_id].size;
	p = Net_conns[conn_id].buffer;
	totlen = 0;
/*
	count = 1;
*/
	while( size > 0 && count > 0 )
	{
/*
		would this be better? not sure afterwards...
		nbytes = (size < count) ? size : count;
		if( (len = readsock(Net_conns[conn_id].channel, p, (size_t)nbytes, 0)) <= 0 ) 
*/
		if( (len = (int)readsock(Net_conns[conn_id].channel, p, (size_t)size, 0)) <= 0 ) 
		{	/* Connection closed by other side. */
			Net_conns[conn_id].read_rout( conn_id, -1, 0 );
			return 0;
		} 
		else 
		{
			
			/*
			printf("tcpip: read %d bytes:\n",len); 
			printf( "buffer[0]=%d\n", vtohl((int *)p[0]));
			printf( "buffer[1]=%d\n", vtohl((int *)p[1]));
			printf( "buffer[2]=%x\n", vtohl((int *)p[2]));
			*/
			totlen += len;
			size -= len;
			p += len;
		}
		if(size)
			count = get_bytes_to_read(conn_id);
	}

	Net_conns[conn_id].last_used = time(NULL);
	Net_conns[conn_id].read_rout( conn_id, 1, totlen );
	return 1;
}
Exemple #2
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);
}
Exemple #3
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, efds, *pfds;
	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 );
		FD_ZERO(&efds);
#ifdef WIN32
		pfds = &efds;
#else
		pfds = &rfds;
#endif
		FD_SET( DIM_IO_path[0], pfds );
		ret = select(FD_SETSIZE, &rfds, NULL, &efds, NULL);
		if(ret > 0)
		{
			if(FD_ISSET(DIM_IO_path[0], pfds) )
			{
#ifndef WIN32
				read(DIM_IO_path[0], &data, 4);
				DIM_IO_Done = 0;
#endif
				FD_CLR( (unsigned)DIM_IO_path[0], pfds );
			}
/*
			{
			DISABLE_AST
*/
			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
				}
				FD_CLR( (unsigned)Net_conns[conn_id].channel, &rfds );
			}
/*
			ENABLE_AST
			}
*/
#ifndef WIN32
			return;
#endif
		}