/** * End loading dictionary entries. It calculates some statistics for * the read entries, outputs errors if encountered * while the last loading, and returns with status whether an error * occured while loading. * * @param winfo [i/o] word dictionary just read by voca_load_line() calls * * @return TRUE when no error has been occured during loading, or FALSE * if an error occured. * */ boolean voca_load_end(WORD_INFO *winfo) { voca_set_stats(winfo); if (!winfo->ok_flag) { if (winfo->errph_root != NULL) list_error(winfo); } return(winfo->ok_flag); }
t_list *list_swap_elem(t_list *a, t_list *b) { void *data; if (!a || !b) list_error("Null element"); data = a->data; a->data = b->data; b->data = data; return (a); }
t_list *list_pop(t_list **begin) { t_list *pop; if (!begin) list_error("Null argument."); pop = *begin; if (pop) { (*begin)->prev = NULL; *begin = pop->next; pop->prev = NULL; pop->next = NULL; } return (pop); }
/** * @brief Create sender list * */ void create_list(char *data_ptr, My402List *list, const char *list_type){ // Initialize the data list if (My402ListInit(list)==0){ exit(1); } // Iterate and add nodes with seq_num and mem address vlong seq_num = 0; for (;seq_num<globals.config.total_size; seq_num += globals.config.packet_size){ struct node *data_node = malloc(sizeof(struct node)); data_node->seq_num = seq_num; data_node->mem_ptr = data_ptr + seq_num; // To handle scenario where the last packet is of size less then // required vlong size = globals.config.total_size - seq_num > globals.config.packet_size ? globals.config.packet_size : globals.config.total_size - seq_num; // size in bytes data_node->size = size; My402ListElem *link_node; if (My402ListAppend(list , data_node, &link_node)==0) list_error("Append Failed"); //DBG("MEM PTR = %p, SEQ_NUM = %llu", data_node->mem_ptr, data_node->seq_num); // Check if DATA or NACK list // Add the linked list node pointer to the hashmap node if (strcmp(list_type, DATA) == 0) { // DATA list hashed_link *hash_node = malloc(sizeof(hashed_link)); hash_node->seq_num = data_node->seq_num; hash_node->data_node_ptr = link_node; add_hashl(hash_node); } else { // NACK list hashed_link *hash_node = (hashed_link *)(find_hashl(data_node->seq_num)); if (!hash_node) { DBG("This should never happen"); exit(1); } hash_node->nack_node_ptr = link_node; } } }
/** * @brief Append node for retransmission * NOT USED */ void add_retransmission_node(vlong *retrans_list, int num_retrans){ // Iterate the retrans_list int i; for (i=0;i<num_retrans;i++){ vlong seq_num = retrans_list[i]; DBG("Add node = %llu", seq_num); hashed_link *hash_node = (hashed_link *)(find_hashl(seq_num)); // Create a duplicate node struct node *data_node = malloc(sizeof(struct node)); data_node->seq_num = seq_num; data_node->mem_ptr = ((struct node*)((hash_node->data_node_ptr)->obj))->mem_ptr; data_node->size = ((struct node*)((hash_node->data_node_ptr)->obj))->size; // Append the duplicate node to the end of the data list. My402ListElem *link_node; if (My402ListAppend(&globals.datal , data_node, &link_node)==0) list_error("Error in appending to list"); } }
/** * @brief Create list * recv_data_list * recv_nack__list * only sequence number is added */ void create_recv_list(My402List *list, const char *list_type){ // Initialize the data list if (My402ListInit(list)==0){ exit(1); } // Iterate and add nodes with seq_num and mem address vlong seq_num = 0; for (;seq_num<globals.config.total_size; seq_num += globals.config.packet_size){ struct node *data_node = malloc(sizeof(struct node)); data_node->seq_num = seq_num; data_node->mem_ptr = NULL; My402ListElem *link_node; if (My402ListAppend(list , data_node, &link_node)==0) list_error("Append Failed"); // Check if DATA or NACK list // Add the linked list node pointer to the hashmap node if (strcmp(list_type, DATA) == 0) { // DATA list hashed_link *hash_node = malloc(sizeof(hashed_link)); hash_node->seq_num = data_node->seq_num; hash_node->data_node_ptr = link_node; add_hashl(hash_node); } else { // NACK list hashed_link *hash_node = (hashed_link *)(find_hashl(data_node->seq_num)); if (!hash_node) { DBG("This should never happen"); exit(1); } hash_node->nack_node_ptr = link_node; } } }