void test_linked_list(){ linked_list_t testList = 0; linked_item_t itemA; linked_item_t itemB; linked_item_t itemC; linked_item_set_user(&itemA, (void *) 0); linked_item_set_user(&itemB, (void *) 0); linked_list_add(&testList, &itemA); linked_list_add(&testList, &itemB); linked_list_add_tail(&testList, &itemC); // linked_list_remove(&testList, &itemB); linked_item_t *it; for (it = (linked_item_t *) &testList; it ; it = it->next){ if (it->next == &itemA) printf("Item A\n"); if (it->next == &itemB) printf("Item B\n"); if (it->next == &itemC) printf("Item C\n"); /* if (it->next == &itemB){ it->next = it->next; printf(" remove\n"); } else { printf(" keep\n"); */ } }
void rb_prio_inorder_walk_node(rb_tree *t, rb_node *n, linked_list*l){ if (n->left != t->nil) rb_prio_inorder_walk_node(t, n->left, l); linked_list_add_tail(n->key, l); if (n->right != t->nil) rb_prio_inorder_walk_node(t, n->right, l); }
void get_keys(rb_tree * tree, rb_node * n, uint32_t height, uint32_t cutoff, linked_list * ll){ if (height > cutoff) linked_list_add_tail(n->key, ll); if (n->left != tree->nil) get_keys(tree, n->left, height+1, cutoff, ll); if (n->right != tree->nil) get_keys(tree, n->right, height+1, cutoff, ll); }
int socket_connection_hci_process(struct data_source *ds) { connection_t *conn = (connection_t *) ds; int bytes_read = read(ds->fd, &conn->buffer[conn->bytes_read], conn->bytes_to_read); if (bytes_read <= 0){ // connection broken (no particular channel, no date yet) socket_connection_emit_connection_closed(conn); // free connection socket_connection_free_connection(linked_item_get_user(&conn->item)); socket_connection_emit_nr_connections(); return 0; } conn->bytes_read += bytes_read; conn->bytes_to_read -= bytes_read; // hexdump( conn->buffer, conn->bytes_read); if (conn->bytes_to_read > 0) { return 0; } int dispatch = 0; switch (conn->state){ case SOCKET_W4_HEADER: conn->state = SOCKET_W4_DATA; conn->bytes_to_read = READ_BT_16( conn->buffer, 4); if (conn->bytes_to_read == 0){ dispatch = 1; } break; case SOCKET_W4_DATA: dispatch = 1; break; default: break; } if (dispatch){ // dispatch packet !!! connection, type, channel, data, size int dispatch_err = (*socket_connection_packet_callback)(conn, READ_BT_16( conn->buffer, 0), READ_BT_16( conn->buffer, 2), &conn->buffer[sizeof(packet_header_t)], READ_BT_16( conn->buffer, 4)); // reset state machine socket_connection_init_statemachine(conn); // "park" if dispatch failed if (dispatch_err) { log_info("socket_connection_hci_process dispatch failed -> park connection\n"); run_loop_remove_data_source(ds); linked_list_add_tail(&parked, (linked_item_t *) ds); } } return 0; }
void ieee80211_psm_add_awake_node(struct ar9170* ar, U8* sa) { U8* awake_node = (U8*)smalloc(ETH_ALEN); if (!awake_node) { printf("ERROR: No memory for allocation of SA for awake list.\n"); return; } memcpy(awake_node, sa, ETH_ALEN); if (ar->ps_mgr.wake_neighbors_list == NULL) { printf("WARNING: Neighbors' List is Null. Should not occur.\n"); ar->ps_mgr.wake_neighbors_list = linked_list_init(ar->ps_mgr.wake_neighbors_list); } /* We do not need to protect this list from interrupts, as no interrupt access it. */ int position = linked_list_add_tail(ar->ps_mgr.wake_neighbors_list, awake_node, AR9170_PSM_MAX_AWAKE_NODES_LIST_LEN, true); if (position < 0) { printf("WARNING: IBSS; Awake not could not be added to the intended list.\n"); } #if IBSS_PSM_DEBUG_DEEP printf("DEBUG: PSM; Node is added to the list in position: %d.\n", position); #endif }