Esempio n. 1
0
int
owlist_free_all
(
	OWList * list,
	void (* free_element) (void *)
)
{
	int return_code = 0 ;
	OWListIterator * iterator ;
	void * element ;

	iterator = owlist_iterator_new (list, OWLIST_WRITE) ;
	if (iterator != NULL)
	{
		while (owlist_iterator_next (iterator) == 0)
		{
			element = owlist_iterator_get (iterator) ;
			return_code |= owlist_iterator_remove (iterator) ;
			free_element (element) ;
			/* if free_element has a return code, it cannot be tested */
		}
		return_code |= owlist_iterator_free (iterator) ;
	}

	return_code |= owlist_free (list) ;

	return return_code ;
}
Esempio n. 2
0
int
transport_initialize
(
	TransportRecv recv_callback,
	TransportListenError listen_error_callback
)
{
	transport_recv_callback = recv_callback ;
	transport_listen_error_callback = listen_error_callback ;

	if (owsl_initialize ())
	{
		return -1 ;
	}

	transport_data_socket_list = owlist_new () ;
	if (transport_data_socket_list == NULL)
	{
		owsl_terminate () ;
		return -1 ;
	}

	transport_listening_socket_list = owlist_new () ;
	if (transport_listening_socket_list == NULL)
	{
		owlist_free (transport_data_socket_list) ;
		transport_data_socket_list = NULL ;
		owsl_terminate () ;
		return -1 ;
	}

	if (pthread_mutex_init (& transport_socket_lists_mutex, NULL))
	{
		owlist_free (transport_listening_socket_list) ;
		transport_listening_socket_list = NULL ;
		owlist_free (transport_data_socket_list) ;
		transport_data_socket_list = NULL ;
		owsl_terminate () ;
		return -1 ;
	}

	return 0 ;
}