Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 06c4402f7d
Fetching contributors…

Cannot retrieve contributors at this time

file 54 lines (46 sloc) 1.289 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
#include "lcb_luv_internal.h"

struct my_timer_st {
    uv_timer_t uvt;
    lcb_luv_callback_t callback;
    void *cb_arg;
};


static void
timer_cb(uv_timer_t *uvt, int status)
{
    struct my_timer_st *timer = (struct my_timer_st*)uvt;
    if (timer->callback) {
        timer->callback(-1, 0, timer->cb_arg);
    }
}

void *
lcb_luv_create_timer(struct libcouchbase_io_opt_st *iops)
{
    struct my_timer_st *timer = calloc(1, sizeof(*timer));
    uv_timer_init(IOPS_COOKIE(iops)->loop, &timer->uvt);
    return timer;
}

int
lcb_luv_update_timer(struct libcouchbase_io_opt_st *iops,
                     void *timer_opaque,
                     libcouchbase_uint32_t usec,
                     void *cbdata,
                     lcb_luv_callback_t callback)
{
    struct my_timer_st *timer = (struct my_timer_st*)timer_opaque;
    timer->callback = callback;
    timer->cb_arg = cbdata;
    return uv_timer_start(&timer->uvt, timer_cb, usec, 0);
}


void
lcb_luv_delete_timer(struct libcouchbase_io_opt_st *iops,
                     void *timer_opaque)
{
    uv_timer_stop((uv_timer_t*)timer_opaque);
}

void
lcb_luv_destroy_timer(struct libcouchbase_io_opt_st *iops,
                      void *timer_opaque)
{
    lcb_luv_delete_timer(iops, timer_opaque);
    free(timer_opaque);
}
Something went wrong with that request. Please try again.