Exemplo n.º 1
0
bool quit_agent(int argc, char *argv[]) {
    op_ptr op = op_list;
    word_t w;
    while (op) {
	op_ptr ele = op;
	op = ele->next;
	free_block(ele, sizeof(op_ele));
    }
    if (router_fd_array)
	free_array(router_fd_array, nrouters, sizeof(int));
    /* Free any pending operations */
    chunk_ptr msg;
    keyvalue_iterstart(operator_table);
    while (keyvalue_removenext(operator_table, NULL, (word_t *) &msg)) {
	chunk_free(msg);
    }
    keyvalue_free(operator_table);
    keyvalue_iterstart(deferred_operand_table);
    while (keyvalue_removenext(deferred_operand_table, NULL, &w)) {
	operand_ptr ls = (operand_ptr) w;
	while (ls) {
	    chunk_free(ls->operand);
	    operand_ptr ele = ls;
	    ls = ls->next;
	    free_block(ele, sizeof(operand_ele));
	}
    }
    keyvalue_free(deferred_operand_table);
    chunk_deinit();
    return true;
}
Exemplo n.º 2
0
int chunk_pool_deinit(chunk_pool_t *cpool) {
    if(!cpool) {
        return EINVAL;
    }
    
    int err = list_deinit(cpool->free_chunks);
    if(err) return err;
    
    err = list_deinit(cpool->zero_chunks);
    if(err) return err;
    
    err = ht_deinit(cpool->hash);
    
    int i = 0; int j = 0;
    for(i; i < cpool->loafs_count; i++) {
        for(j; j < DEFAULT_ARRAY_SIZE; j++) {
            chunk_deinit(&(cpool->loafs)[i][j]);
        }
        free((cpool->loafs)[i]);
    }
    free(cpool->loafs);
    
    err = close(cpool->fd);
    if(err == -1) return errno;
    free(cpool);
    
    return 0;
}
Exemplo n.º 3
0
bool quit_controller(int argc, char *argv[]) {
    /* Send kill messages to other nodes and close file connections */
    chunk_ptr msg = msg_new_kill();
    word_t w;
    int fd;
    keyvalue_iterstart(new_conn_map);
    while (keyvalue_iternext(new_conn_map, &w, NULL)) {
	fd = w;
	close(fd);
    }
    set_iterstart(router_fd_set);
    while (set_iternext(router_fd_set, &w)) {
	fd = w;
	if (!chunk_write(fd, msg))
	    err(false,
		"Failed to send kill message to router with descriptor %d", fd);
	close(fd);
    }
    set_iterstart(worker_fd_set);
    while (set_iternext(worker_fd_set, &w)) {
	fd = w;
	if (!chunk_write(fd, msg))
	    err(false,
		"Failed to send kill message to worker with descriptor %d", fd);
	close(fd);
    }
    set_iterstart(client_fd_set);
    while (set_iternext(client_fd_set, &w)) {
	fd = w;
	if (!chunk_write(fd, msg))
	    err(false,
		"Failed to send kill message to client with descriptor %d", fd);
	close(fd);
    }
    /* Deallocate */
    chunk_free(msg);
    set_free(router_addr_set);
    keyvalue_free(new_conn_map);
    set_free(router_fd_set);
    set_free(worker_fd_set);
    set_free(client_fd_set);
    while (stat_message_cnt > 0) {
	chunk_free(stat_messages[--stat_message_cnt]);
    }
    free_array(stat_messages, sizeof(chunk_ptr), worker_cnt);
    free_global_ops();
    if (need_client_fd_set != NULL)
	set_free(need_client_fd_set);
    need_client_fd_set = NULL;
    if (defer_client_fd_set != NULL)
	set_free(defer_client_fd_set);
    defer_client_fd_set = NULL;
    chunk_deinit();
    return true;
}