void listCheck(Connection * previous, Connection * current) { DEBUGOUT("in listCheck"); if(current && !(current->status.is_alive)) { previous->next = current->next; delConnection(current); listCheck(previous, previous->next); } return; }
void listFree(list *lst) { assert(listCheck(lst)); if(lst->current) { listnode *start = lst->current; do { listnode *next = lst->current->next; free(lst->current); lst->current = next; } while(lst->current != start); } free(lst); }
void listDeleteCurrent(list *lst) { assert(lst && lst->current && listCheck(lst)); listnode *next = lst->current->next, *prev = lst->current->prev; free(lst->current); lst->size--; if(lst->size == 0) { lst->current = NULL; } else { lst->current = next; next->prev = prev; prev->next = next; } }
void reapConnections(Server * srv) { void listCheck(Connection * previous, Connection * current); DEBUGOUT("in reapConnections\n"); if(srv->conList && srv->conList->next) { listCheck(srv->conList, srv->conList->next); } else if(srv->conList && !(srv->conList->next) && !(srv->conList->status.is_alive)) { delConnection(srv->conList); srv->conList = NULL; } else DEBUGOUT("NOTHING\n"); DEBUGOUT("reapConnections returning\n"); return; }
void listInsert(list *lst, void *data) { assert(lst && listCheck(lst)); listnode *node = malloc(sizeof(listnode)); if(lst->current) { node->next = lst->current; node->prev = lst->current->prev; node->prev->next = node; node->next->prev = node; if(lst->current->next == lst->current) { lst->current->next = node; } } else { node->next = node; node->prev = node; } lst->current = node; node->data = data; lst->size++; }
void listMoveBack(list *lst) { assert(lst && listCheck(lst)); if(lst->current) lst->current = lst->current->prev; }
int listSize(list *lst) { assert(lst && listCheck(lst)); return lst->size; }
void *listGetCurrent(list *lst) { assert(lst && lst->current && listCheck(lst)); return lst->current->data; }
void listMoveForward(list *lst) { assert(lst && listCheck(lst)); if(lst->current) lst->current = lst->current->next; }