Fix deleting connections from the connection list.
This commit is contained in:
		
							parent
							
								
									0b8b23e0dd
								
							
						
					
					
						commit
						f62b4a9134
					
				
					 3 changed files with 12 additions and 9 deletions
				
			
		|  | @ -91,12 +91,7 @@ void connection_add(connection_t *c) { | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void connection_del(connection_t *c) { | void connection_del(connection_t *c) { | ||||||
| 	for list_each(connection_t, c, connection_list) { | 	list_delete(connection_list, c); | ||||||
| 		if(node->data == c) { |  | ||||||
| 			list_delete_node(connection_list, node); |  | ||||||
| 			return; |  | ||||||
| 		} |  | ||||||
| 	} |  | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| bool dump_connections(connection_t *cdump) { | bool dump_connections(connection_t *cdump) { | ||||||
|  |  | ||||||
							
								
								
									
										12
									
								
								src/list.c
									
										
									
									
									
								
							
							
						
						
									
										12
									
								
								src/list.c
									
										
									
									
									
								
							|  | @ -150,6 +150,12 @@ void list_delete_tail(list_t *list) { | ||||||
| 	list_delete_node(list, list->tail); | 	list_delete_node(list, list->tail); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | void list_delete(list_t *list, const void *data) { | ||||||
|  | 	for(list_node_t *node = list->head, *next; next = node ? node->next : NULL, node; node = next) | ||||||
|  | 		if(node->data == data) | ||||||
|  | 			list_delete_node(list, node); | ||||||
|  | } | ||||||
|  | 
 | ||||||
| /* Head/tail lookup */ | /* Head/tail lookup */ | ||||||
| 
 | 
 | ||||||
| void *list_get_head(list_t *list) { | void *list_get_head(list_t *list) { | ||||||
|  | @ -169,7 +175,7 @@ void *list_get_tail(list_t *list) { | ||||||
| /* Fast list deletion */ | /* Fast list deletion */ | ||||||
| 
 | 
 | ||||||
| void list_delete_list(list_t *list) { | void list_delete_list(list_t *list) { | ||||||
| 	for(list_node_t *node = list->head, *next; next = node->next, node; node = next) | 	for(list_node_t *node = list->head, *next; next = node ? node->next : NULL, node; node = next) | ||||||
| 		list_free_node(list, node); | 		list_free_node(list, node); | ||||||
| 
 | 
 | ||||||
| 	list_free(list); | 	list_free(list); | ||||||
|  | @ -178,12 +184,12 @@ void list_delete_list(list_t *list) { | ||||||
| /* Traversing */ | /* Traversing */ | ||||||
| 
 | 
 | ||||||
| void list_foreach_node(list_t *list, list_action_node_t action) { | void list_foreach_node(list_t *list, list_action_node_t action) { | ||||||
| 	for(list_node_t *node = list->head, *next; next = node->next, node; node = next) | 	for(list_node_t *node = list->head, *next; next = node ? node->next : NULL, node; node = next) | ||||||
| 		action(node); | 		action(node); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void list_foreach(list_t *list, list_action_t action) { | void list_foreach(list_t *list, list_action_t action) { | ||||||
| 	for(list_node_t *node = list->head, *next; next = node->next, node; node = next) | 	for(list_node_t *node = list->head, *next; next = node ? node->next : NULL, node; node = next) | ||||||
| 		if(node->data) | 		if(node->data) | ||||||
| 			action(node->data); | 			action(node->data); | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -57,6 +57,8 @@ extern list_node_t *list_insert_tail(list_t *, void *); | ||||||
| extern list_node_t *list_insert_after(list_t *, list_node_t *, void *); | extern list_node_t *list_insert_after(list_t *, list_node_t *, void *); | ||||||
| extern list_node_t *list_insert_before(list_t *, list_node_t *, void *); | extern list_node_t *list_insert_before(list_t *, list_node_t *, void *); | ||||||
| 
 | 
 | ||||||
|  | extern void list_delete(list_t *, const void *); | ||||||
|  | 
 | ||||||
| extern void list_unlink_node(list_t *, list_node_t *); | extern void list_unlink_node(list_t *, list_node_t *); | ||||||
| extern void list_delete_node(list_t *, list_node_t *); | extern void list_delete_node(list_t *, list_node_t *); | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue