/** * Remove expired connections from NAT. */ void nat_cleaning(void) { linkedlist_node_t *tmp; time_t curtime = time(NULL); /* TCP FRAGMENTS [2 secs] */ tmp = timeout_tcp_fragments->first.next; while (tmp->next != NULL && curtime - tmp->time >= 2) { tmp = tmp->next; /* destroy queue */ linkedlist_destroy(((struct s_nat_fragments *) tmp->prev->data)->queue); /* remove connection */ nat_in_fragments_cleanup(nat4_tcp_fragments, ((struct s_nat_fragments *) tmp->prev->data)->connection->ipv4, ((struct s_nat_fragments *) tmp->prev->data)->id); free(((struct s_nat_fragments *) tmp->prev->data)->connection); free(tmp->prev->data); linkedlist_delete(timeout_tcp_fragments, tmp->prev); } /* ICMP [60 secs] */ tmp = timeout_icmp->first.next; while (tmp->next != NULL && curtime - tmp->time >= 60) { tmp = tmp->next; nat_delete_connection(nat4_icmp, nat6_icmp, tmp->prev->data); linkedlist_delete(timeout_icmp, tmp->prev); } /* TCP -- TRANS [4 mins] */ tmp = timeout_tcp_trans->first.next; while (tmp->next != NULL && curtime - tmp->time >= 4 * 60) { tmp = tmp->next; nat_delete_connection(nat4_tcp, nat6_tcp, tmp->prev->data); linkedlist_delete(timeout_tcp_trans, tmp->prev); } /* UDP [5 mins (minimum is 2 mins)] */ tmp = timeout_udp->first.next; while (tmp->next != NULL && curtime - tmp->time >= 5 * 60) { tmp = tmp->next; nat_delete_connection(nat4_udp, nat6_udp, tmp->prev->data); linkedlist_delete(timeout_udp, tmp->prev); } /* TCP -- EST [2 hrs and 4 mins] */ tmp = timeout_tcp_est->first.next; while (tmp->next != NULL && curtime - tmp->time >= 124 * 60) { tmp = tmp->next; nat_delete_connection(nat4_tcp, nat6_tcp, tmp->prev->data); linkedlist_delete(timeout_tcp_est, tmp->prev); } }
void knDestroyQueue(knQueue_t* que) { if(que == NULL) { return; } #ifdef _SW_Q_ linkedlist_delete(que->queue, knReleaseEventNode); #else msgctl(que->fd, IPC_RMID, 0); #endif KnOSDeleteMutex(que->lock); KnOSDeleteSemaphore(que->event); KnFree(que); }
void lazyworker_delete(lazyworker lazy) { if(lazy == NULL) { fprintf(stderr, "NULL\n"); } _lazyworker_t* worker = (_lazyworker_t*) lazy; pthread_mutex_lock(&worker->mutex); worker->threadStatus = eThreadStatus_CLOSED; pthread_cond_broadcast(&worker->cond); pthread_mutex_unlock(&worker->mutex); pthread_join(worker->thread, NULL); pthread_mutex_destroy(&worker->mutex); pthread_cond_destroy(&worker->cond); linkedlist_delete(worker->sth_todo, NULL); free(worker); return; }
int main (int argc, char *argv[]) { int rv; int result; int i, j, count; linkedlist_t sll; linkedlist_node_t *node; void *value; void *found; rv = linkedlist_init(&sll, 1, compare_pointers, NULL); if (rv) { fprintf(stderr, "linkedlist_init failed: %d\n", rv); return rv; } else { printf("list initialized\n"); } flush(); for (i = START_INT; i <= END_INT; i++) { value = integer2pointer(i); rv = linkedlist_add_once(&sll, value, &found); if (rv) { fprintf(stderr, "adding %d failed\n", i); } hashmap[i] = 1; rv = linkedlist_add_once(&sll, value, &found); if (rv) { fprintf(stderr, "adding %d failed in 2nd attempt\n", i); } rv = linkedlist_add_once(&sll, value, &found); if (rv) { fprintf(stderr, "adding %d failed in 3rd attempt\n", i); } } printf("all %d items added to list\n", sll.n); assert(sll.n == (END_INT - START_INT + 1)); flush(); printf("checking that the list is ordered\n"); node = sll.head; result = -1000; while (not_endof_linkedlist(node)) { printf("%lld ", pointer2integer(node->user_data)); if (pointer2integer(node->user_data) < result) { fprintf(stderr, "list order incorrect, current: %lld expected: >= %d\n", pointer2integer(node->user_data), result); result = pointer2integer(node->user_data); } node = node->next; } printf("\n"); fflush(stdout); fflush(stdout); /* now delete one at a time and make sure everything is consistent */ printf("now deleting and verifying one at a time\n"); flush(); count = sll.n; int *s, *d; for (i = END_INT; i >= START_INT; i--) { rv = linkedlist_delete(&sll, integer2pointer(i), (void**) &d); if (rv == 0) { count--; assert(count == sll.n); assert(integer2pointer(i) == d); hashmap[i] = 0; /* * make sure that the deleted entry is NOT in the list * but ALL others are */ for (j = START_INT; j <= END_INT; j++) { if (hashmap[j]) { assert(linkedlist_search(&sll, integer2pointer(j), (void**)&s) == 0); assert(j == pointer2integer(s)); } else { assert(linkedlist_search(&sll, integer2pointer(j), (void**)&s) == ENODATA); } } } else { fprintf(stderr, "linkedlist_delete for %d failed\n", i); } } assert(sll.n == 0); printf("all data verified, list is sane\n"); return 0; }
int linkedlist_shift(p_linkedlist_t p_head, int *val) { return linkedlist_delete(p_head, 0, val); }
int linkedlist_pop(p_linkedlist_t p_head, int *val) { return linkedlist_delete(p_head, linkedlist_length(p_head), val); }