Ejemplo n.º 1
0
static void teardown(void)
{
    lcb_destroy(session);
    lcb_destroy_io_ops(io);
    session = NULL;
    io = NULL;
    shutdown_mock_server(mock);
    mock = NULL;
}
Ejemplo n.º 2
0
static lcb_error_t test_connect(char **argv, const char *username,
                                const char *password,
                                const char *bucket)
{
    const char *endpoint;
    lcb_error_t rc;
    struct lcb_create_st options;

    lcb_assert(session == NULL);
    lcb_assert(mock == NULL);
    lcb_assert(io == NULL);

    if (lcb_create_io_ops(&io, NULL) != LCB_SUCCESS) {
        fprintf(stderr, "Failed to create IO instance\n");
        exit(1);
    }

    mock = start_test_server(argv);
    if (mock == NULL) {
        err_exit("Failed to start mock server");
    }

    endpoint = get_mock_http_server(mock);

    memset(&options, 0, sizeof(options));
    options.version = 2;
    options.v.v2.host = endpoint;
    options.v.v2.user = username;
    options.v.v2.passwd = password;
    options.v.v2.bucket = bucket;
    options.v.v2.io = io;
    options.v.v2.transports = enabled_transports;

    if (lcb_create(&session, &options) != LCB_SUCCESS) {
        err_exit("Failed to create libcouchbase session");
    }

    (void)lcb_set_error_callback(session, error_callback2);

    if (lcb_connect(session) != LCB_SUCCESS) {
        err_exit("Failed to connect to server");
    }
    lcb_wait(session);
    rc = global_error;

    lcb_destroy(session);
    lcb_destroy_io_ops(io);
    session = NULL;
    io = NULL;
    shutdown_mock_server(mock);
    mock = NULL;

    return rc;
}
Ejemplo n.º 3
0
lcb_io_opt_t
pycbc_iops_new(pycbc_Connection *conn, PyObject *pyio)
{
    lcb_io_opt_t ret = NULL;
    lcb_io_opt_t dfl = NULL;

    lcb_error_t err;
    struct lcb_create_io_ops_st options = { 0 };
    pycbc_iops_t *pio;

    pio = calloc(1, sizeof(*pio));
    ret = &pio->iops;
    pio->conn = conn;
    pio->pyio = pyio;

    Py_INCREF(pyio);

    /**
     * We create the select 'iops' handle and copy over its functionality
     * from there. Now that libcouchbase has the 'select' iops build in, we use
     * that instead.
     *
     * We discard the default iops loop data at the expense of leaking a
     * dlhandle.
     */
    options.v.v0.type = LCB_IO_OPS_SELECT;
    err = lcb_create_io_ops(&dfl, &options);
    if (err != LCB_SUCCESS) {
        PYCBC_EXC_WRAP(PYCBC_EXC_LCBERR, err, "Couldn't create IOPS");
        return NULL;
    }

    memcpy(&pio->iops, dfl, sizeof(*dfl));
    /* hide the dlsym */
    dfl->dlhandle = NULL;

    lcb_destroy_io_ops(dfl);
    dfl = NULL;

    ret->v.v0.create_event = create_event;
    ret->v.v0.create_timer = create_timer;
    ret->v.v0.destroy_event = destroy_event_common;
    ret->v.v0.destroy_timer = destroy_event_common;
    ret->v.v0.update_event = update_event;
    ret->v.v0.delete_event = delete_event;
    ret->v.v0.delete_timer = delete_timer;
    ret->v.v0.update_timer = update_timer;
    ret->v.v0.run_event_loop = run_event_loop;
    ret->v.v0.stop_event_loop = stop_event_loop;
    ret->destructor = iops_destructor;

    return ret;
}
Ejemplo n.º 4
0
static lcb_error_t create_v1(lcb_io_opt_t *io,
                             const struct lcb_create_io_ops_st *options)
{
    struct plugin_st plugin;
    int want_debug;
    lcb_error_t ret;

    if (lcb_getenv_boolean_multi("LIBCOUCHBASE_DLOPEN_DEBUG",
        "LCB_DLOPEN_DEBUG", NULL)) {
        want_debug = 1;
    } else {
        want_debug = want_dl_debug;
    }
    ret = get_create_func(options->v.v1.sofile,
                          options->v.v1.symbol, &plugin, want_debug);
    if (ret != LCB_SUCCESS) {
        /* try to look up the symbol in the current image */
        lcb_error_t ret2 = get_create_func(NULL, options->v.v1.symbol, &plugin, want_debug);
        if (ret2 != LCB_SUCCESS) {
#ifndef _WIN32
            char path[PATH_MAX];
            /* try to look up the so-file in the libdir */
            snprintf(path, PATH_MAX, "%s/%s", LCB_LIBDIR, options->v.v1.sofile);
            ret2 = get_create_func(path, options->v.v1.symbol, &plugin, want_debug);
#endif
            if (ret2 != LCB_SUCCESS) {
                /* return original error to allow caller to fix it */
                return ret;
            }
        }
    }

    ret = plugin.func.create(0, io, options->v.v1.cookie);
    if (ret != LCB_SUCCESS) {
        if (options->v.v1.sofile != NULL) {
            close_dlhandle(plugin.dlhandle);
        }
        return LCB_CLIENT_ENOMEM;
    } else {
        lcb_io_opt_t iop = *io;
        iop->dlhandle = plugin.dlhandle;
        /* check if plugin selected compatible version */
        if (iop->version < 0 || iop->version > 2) {
            lcb_destroy_io_ops(iop);
            return LCB_PLUGIN_VERSION_MISMATCH;
        }
    }

    return LCB_SUCCESS;
}
Ejemplo n.º 5
0
static lcb_error_t create_v2(lcb_io_opt_t *io,
                             const struct lcb_create_io_ops_st *options)
{
    lcb_error_t ret;

    ret = options->v.v2.create(0, io, options->v.v2.cookie);
    if (ret != LCB_SUCCESS) {
        return ret;
    } else {
        lcb_io_opt_t iop = *io;
        /* check if plugin selected compatible version */
        if (iop->version < 0 || iop->version > 2) {
            lcb_destroy_io_ops(iop);
            return LCB_PLUGIN_VERSION_MISMATCH;
        }
    }

    return LCB_SUCCESS;
}
static void
ngx_lcb_exit_process(ngx_cycle_t *cycle)
{
    lcb_destroy_io_ops(lcb_cookie.io);
    (void)cycle;
}
Ejemplo n.º 7
0
LIBCOUCHBASE_API
void lcb_destroy(lcb_t instance)
{
    lcb_size_t ii;
    lcb_settings *settings = &instance->settings;

    if (instance->cur_configinfo) {
        lcb_clconfig_decref(instance->cur_configinfo);
        instance->cur_configinfo = NULL;
    }
    instance->vbucket_config = NULL;

    lcb_bootstrap_destroy(instance);
    lcb_confmon_destroy(instance->confmon);
    hostlist_destroy(instance->usernodes);

    if (instance->timers != NULL) {
        for (ii = 0; ii < instance->timers->capacity; ++ii) {
            if (instance->timers->items[ii] > 1) {
                lcb_timer_destroy(instance,
                                  (lcb_timer_t)instance->timers->items[ii]);
            }
        }
        hashset_destroy(instance->timers);
    }

    if (instance->durability_polls) {
        struct lcb_durability_set_st **dset_list;
        lcb_size_t nitems = hashset_num_items(instance->durability_polls);
        dset_list = (struct lcb_durability_set_st **)
                    hashset_get_items(instance->durability_polls, NULL);
        if (dset_list) {
            for (ii = 0; ii < nitems; ii++) {
                lcb_durability_dset_destroy(dset_list[ii]);
            }
            free(dset_list);
        }
        hashset_destroy(instance->durability_polls);
    }

    for (ii = 0; ii < instance->nservers; ++ii) {
        lcb_server_destroy(instance->servers + ii);
    }

    if (instance->http_requests) {
        for (ii = 0; ii < instance->http_requests->capacity; ++ii) {
            if (instance->http_requests->items[ii] > 1) {
                lcb_http_request_t htreq =
                    (lcb_http_request_t)instance->http_requests->items[ii];

                /**
                 * We don't want to invoke callbacks *or* remove it from our
                 * hash table
                 */
                htreq->status |= LCB_HTREQ_S_CBINVOKED | LCB_HTREQ_S_HTREMOVED;

                /* we should figure out a better error code for this.. */
                lcb_http_request_finish(instance, htreq, LCB_ERROR);
            }
        }
    }

    hashset_destroy(instance->http_requests);

    free(instance->servers);

    connmgr_destroy(instance->memd_sockpool);

    if (settings->io && settings->io->v.v0.need_cleanup) {
        lcb_destroy_io_ops(settings->io);
    }

    ringbuffer_destruct(&instance->purged_buf);
    ringbuffer_destruct(&instance->purged_cookies);

    free(instance->histogram);
    free(instance->scratch);
    free(settings->username);
    free(settings->password);
    free(settings->bucket);
    free(settings->sasl_mech_force);
    if (instance->cmdht) {
        genhash_free(instance->cmdht);
        instance->cmdht = NULL;
    }

    memset(instance, 0xff, sizeof(*instance));
    free(instance);
}