Exemple #1
0
int main(int argc, char **argv) {
    whatever w = {0};
    w.alloc = malloc(5);
    nitro_counted_buffer_t *buf = nitro_counted_buffer_new(
        w.alloc, my_free, &w);
    TEST("cbuffer non-null", buf);
    nitro_counted_buffer_decref(buf);
    TEST("marked done", w.gone);

    whatever w2 = {0};
    w2.alloc = malloc(5);
    buf = nitro_counted_buffer_new(
        w2.alloc, my_free, &w2);
    int i = 0;
    for (i=0; i < 200; i++) {
        nitro_counted_buffer_incref(buf);
        nitro_counted_buffer_decref(buf);
    }
    TEST("not marked done", !w2.gone);
    for (i=0; i < 200; i++) {
        nitro_counted_buffer_incref(buf);
    }
    TEST("not marked done", !w2.gone);
    for (i=0; i < 200; i++) {
        nitro_counted_buffer_decref(buf);
    }
    TEST("not marked done", !w2.gone);
    nitro_counted_buffer_decref(buf);
    TEST("marked done", w2.gone);

    SUMMARY(0);
    return 1;
}
Exemple #2
0
int Sinproc_socket_bind(nitro_inproc_socket_t *s, char *location) {
    if (Sinproc_check_opt(s) < 0) {
        return -1;
    }

    Sinproc_create_queues(s);

    pthread_mutex_lock(&the_runtime->l_inproc);
    nitro_inproc_socket_t *match;

    s->bound = 1;
    s->bind_counter = nitro_counted_buffer_new(s, free_inproc, NULL);
    pthread_rwlock_init(&s->link_lock, NULL);
    s->current = NULL;

    HASH_FIND(hh, the_runtime->inprocs, location, strlen(location), match);

    if (match) {
        pthread_mutex_unlock(&the_runtime->l_inproc);
        return nitro_set_error(NITRO_ERR_INPROC_ALREADY_BOUND);
    }

    HASH_ADD_KEYPTR(hh, the_runtime->inprocs,
                    s->given_location,
                    strlen(s->given_location),
                    s);
    HASH_FIND(hh, the_runtime->inprocs, location, strlen(location), match);
    assert(match == s);

    pthread_mutex_unlock(&the_runtime->l_inproc);
    return 0;
}
Exemple #3
0
nitro_sockopt_t *nitro_sockopt_new() {
    nitro_sockopt_t *opt;
    ZALLOC(opt);

    /* defaults (otherwise, 0) */
    opt->ident = malloc(SOCKET_IDENT_LENGTH);
    opt->ident_buf = nitro_counted_buffer_new(opt->ident, just_free, NULL);
    opt->close_linger = 1.0;
    opt->reconnect_interval = 0.2; /* seconds */
    opt->max_message_size = 16 * NITRO_MB;

    opt->error_handler = nitro_error_log_handler;
    return opt;
}