コード例 #1
0
ファイル: client_blocking.c プロジェクト: achreto/barrelfish
/**
 * \brief Initialize client state with default values.
 */
static void struct_term_client_init(struct term_client *client)
{
    client->read_ws = malloc(sizeof(struct waitset));
    assert(client->read_ws != NULL);
    waitset_init(client->read_ws);
    client->write_ws = malloc(sizeof(struct waitset));
    assert(client->write_ws != NULL);
    waitset_init(client->write_ws);
    client->conf_ws = malloc(sizeof(struct waitset));
    assert(client->conf_ws);
    waitset_init(client->conf_ws);
    client->connected = false;
    client->echo = true;
    client->line_mode = true;
    client->non_blocking_read = false;
    client->chars_cb = NULL;
    client->err_cb = default_err_handler,
    client->in_binding = NULL;
    client->out_binding = NULL;
    client->conf_binding = NULL;
    client->readbuf = NULL;
    collections_list_create(&client->input_filters, term_filter_free);
    collections_list_create(&client->output_filters, term_filter_free);
    collections_list_create(&client->echo_filters, term_filter_free);
    client->max_input_filter_id = 0;
    client->max_output_filter_id = 0;
    client->max_echo_filter_id = 0;
    collections_list_create(&client->triggers, term_trigger_free);
    client->max_trigger_id = 0;

    /* add default input filters */
    term_client_add_input_filter(client, term_filter_cr2lf);

    /* add default output filters */
    term_client_add_output_filter(client, term_filter_lf2crlf);

    /* add default echo filters */
    term_client_add_echo_filter(client, term_filter_ctrlhat);

    /* add default triggers */
    /* The user can not remove the kill trigger. */
    term_client_add_trigger_type(client, term_trigger_kill,
                                 TERM_TRIGGER_TYPE_BUILT_IN);
    term_client_add_trigger_type(client, term_trigger_int,
                                 TERM_TRIGGER_TYPE_USER);
}
コード例 #2
0
ファイル: hash_table.c プロジェクト: BarrelfishOS/barrelfish
/*
 * Create a hash table.
 */
static void collections_hash_create_core(collections_hash_table **t, int num_buckets, collections_hash_data_free data_free)
{
	int i;

	*t = (collections_hash_table *) malloc (sizeof(collections_hash_table));
	memset(*t, 0, sizeof(collections_hash_table));

	(*t)->num_buckets = num_buckets;

	// create a linked list node for each bucket
	(*t)->buckets = (collections_listnode **) malloc(sizeof(collections_listnode *) * num_buckets);
	for (i = 0; i < num_buckets; i ++) {
		collections_list_create(&(*t)->buckets[i], NULL);
	}

	(*t)->num_elems = 0;
    (*t)->data_free = data_free;

	// to keep track of traversing the hash table
	(*t)->cur_bucket_num = -1;
	return;
}