Ejemplo n.º 1
0
void ntoh_init ( void )
{
	ntoh_tcp_init();
	ntoh_ipv4_init();
	ntoh_ipv6_init();

	return;
}
Ejemplo n.º 2
0
/** @brief API to create a new session and add it to the global sessions list **/
pntoh_tcp_session_t ntoh_tcp_new_session ( unsigned int max_streams , unsigned int max_timewait , unsigned int *error )
{
	pntoh_tcp_session_t session;

	if ( !max_streams )
		max_streams = DEFAULT_TCP_MAX_STREAMS;

	if ( !max_timewait )
		max_timewait = DEFAULT_TCP_MAX_TIMEWAIT_STREAMS(max_streams);

	if ( ! (session = (pntoh_tcp_session_t) calloc ( 1 , sizeof ( ntoh_tcp_session_t ) ) ) )
	{
		if ( error != 0 )
			*error = NTOH_ERROR_NOMEM;
		return 0;
	}

    ntoh_tcp_init();

	session->streams = htable_map ( max_streams );
	session->timewait = htable_map ( max_timewait );

	sem_init ( &session->max_streams , 0 , max_streams );
	sem_init ( &session->max_timewait , 0 , max_timewait );

	session->lock.use = 0;
    pthread_mutex_init( &session->lock.mutex, 0 );
    pthread_cond_init( &session->lock.pcond, 0 );

	srand((int)time(NULL));

	session->rand = rand();


    lock_access ( &params.lock );

    if ( params.sessions_list != 0 )
    	session->next = params.sessions_list;
    params.sessions_list = session;

    unlock_access ( &params.lock );

    if ( error != 0 )
    	*error = NTOH_OK;

    pthread_create ( &session->tID , 0 , timeouts_thread , (void*) session );

	return session;
}