예제 #1
0
void on_conflate_new_config(void *userdata, kvpair_t *config) {
    assert(config != NULL);

    proxy_main *m = userdata;
    assert(m != NULL);

    LIBEVENT_THREAD *mthread = thread_by_index(0);
    assert(mthread != NULL);

    if (settings.verbose > 2) {
        fprintf(stderr, "agent_config ocnc on_conflate_new_config\n");
    }

    work_collect completion;
    work_collect_init(&completion, 1, m);

    kvpair_t *copy = dup_kvpair(config);
    if (copy != NULL) {
        if (!work_send(mthread->work_queue, cproxy_on_new_config, &completion, copy) &&
            settings.verbose > 1) {
            fprintf(stderr, "work_send failed\n");
        }
    } else {
        if (settings.verbose > 1) {
            fprintf(stderr, "agent_config ocnc failed dup_kvpair\n");
        }
    }

    work_collect_wait(&completion);
}
예제 #2
0
kvpair_t *dup_kvpair(kvpair_t *pair)
{
    assert(pair);
    kvpair_t *copy = mk_kvpair(pair->key, pair->values);
    if (pair->next) {
        copy->next = dup_kvpair(pair->next);
    }
    return copy;
}
예제 #3
0
END_TEST

START_TEST (test_copy_pair)
{
    char *args1[] = {"arg1", "arg2", NULL};
    char *args2[] = {"other", NULL};
    kvpair_t *pair1 = mk_kvpair("some_key", args1);
    pair = mk_kvpair("some_other_key", args2);
    pair->next = pair1;

    kvpair_t *copy = dup_kvpair(pair);
    fail_if(copy == NULL, "Copy failed.");
    fail_if(copy == pair, "Copy something not an identity.");

    fail_unless(strcmp(copy->key, pair->key) == 0, "Keys don't match.");
    fail_if(copy->key == pair->key, "Keys were identical.");
    check_pair_equality(pair, copy);

    free_kvpair(copy);
}