Exemple #1
0
lcb_luv_socket_t lcb_luv_socket_new(struct lcb_io_opt_st *iops)
{
    /* Find the next 'file descriptor' */

    lcb_socket_t idx;
    lcb_luv_socket_t newsock;
    idx = find_free_idx(IOPS_COOKIE(iops));
    if (idx == -1) {
        iops->v.v0.error = ENFILE;
        return NULL;
    }

    newsock = calloc(1, sizeof(struct lcb_luv_socket_st));
    newsock->idx = idx;
    newsock->parent = IOPS_COOKIE(iops);

    uv_async_init(newsock->parent->loop, &newsock->async, async_cb);
    newsock->async_state = 0;

    newsock->async.data = newsock;
    newsock->u_req.req.data = newsock;
    newsock->refcount = 1;

    uv_tcp_init(IOPS_COOKIE(iops)->loop, &newsock->tcp);
    IOPS_COOKIE(iops)->socktable[idx] = newsock;
    iops->v.v0.error = 0;
    log_socket_debug("%p: Created new socket %p(%d)", iops, newsock, idx);
    return newsock;
}
Exemple #2
0
static void sync_loop_run(struct lcb_io_opt_st *iops)
{
    log_iops_info("=== LOOP: run ===");
    IOPS_COOKIE(iops)->do_stop = 0;
    /** node's libuv does not export uv_run_once */
#ifdef LCB_LUV_VANILLA
    while (IOPS_COOKIE(iops)->do_stop == 0) {
        uv_run_once(IOPS_COOKIE(iops)->loop);
    }
#endif /* LCB_LUV_NODEJS */
}
Exemple #3
0
static void
lcb_luv_dtor(struct lcb_io_opt_st *iops)
{
    /**
     * First, clean up any dangling sockets
     */
    int ii;
    struct lcb_luv_cookie_st *cookie = IOPS_COOKIE(iops);
    uv_loop_t *l = cookie->loop;

    for (ii = 0; ii < cookie->fd_max; ii++) {
        if (cookie->socktable[ii]) {
            log_iops_warn("Dangling socket structure %p with index %d",
                       cookie->socktable + ii,
                       ii);
        }
    }

    log_iops_debug("Destroying %p", iops);
    log_iops_warn("Still have %d timers", cookie->timer_count);
    assert (cookie->timer_count == 0);
    free (cookie->socktable);
    free (cookie);
    free (iops);
}
Exemple #4
0
static void sync_loop_stop(struct lcb_io_opt_st *iops)
{
    log_iops_info("=== LOOP: stop ===");
    IOPS_COOKIE(iops)->do_stop = 1;
}
Exemple #5
0
static void
invoke_stop_callback(struct lcb_io_opt_st *iops)
{
    invoke_startstop_callback(IOPS_COOKIE(iops), IOPS_COOKIE(iops)->stop_callback);
}
Exemple #6
0
static void
invoke_start_callback(struct lcb_io_opt_st *iops)
{
    log_iops_debug("Start event loop..");
    invoke_startstop_callback(IOPS_COOKIE(iops), IOPS_COOKIE(iops)->start_callback);
}