Example #1
0
socket_t *find_socket( uint16 src_port, uint16 dest_port, int proto )
{
	socket_t *result = 0;
	EnterCriticalSection( &router_section );
	int i = get_socket_index( src_port, dest_port, proto );
	if( i >= 0 ) {
		result = all_sockets[i];
	} else {
		i = get_socket_index( src_port, proto );
		if( i >= 0 ) {
			delete_socket( all_sockets[i] );
		}
	}
	LeaveCriticalSection( &router_section );

  D(bug("find_socket(%d,%d): %s\r\n", src_port, dest_port, result ? "found" : "not found"));

	return result;
}
Example #2
0
static int find_socket( const uint16 src_port, const uint16 dest_port )
{
	int i = get_socket_index( src_port, dest_port );
	if( i < 0 ) {
		i = get_socket_index( src_port );
		if( i >= 0 ) {
			if( sockets[i].s == INVALID_SOCKET ) {
			  D(bug("find_socket reusing slot %d...\r\n", i));
				sockets[i].in_use = false;
			} else {
			  D(bug("find_socket forcing close %d...\r\n", i));
				free_socket( i );
			}
			i = -1;
		}
	}

  D(bug("<%d> find_socket(%d,%d): %s\r\n", i, src_port, dest_port, i>=0 ? "found" : "not found"));

	return i;
}
Example #3
0
void delete_socket( socket_t *cmpl )
{
  D(bug("deleting socket(%d,%d)\r\n", cmpl->src_port, cmpl->dest_port));

	EnterCriticalSection( &router_section );
	int i = get_socket_index( cmpl );
	if( i >= 0 ) {
		delete all_sockets[i];
		all_sockets[i] = all_sockets[--open_sockets];
	} else {
	  D(bug("Deleted socket not in table!\r\n"));
		// delete cmpl;
	}
	LeaveCriticalSection( &router_section );
}