Skip to content

Instantly share code, notes, and snippets.

@Quby
Created January 5, 2012 14:16
Show Gist options
  • Select an option

  • Save Quby/1565434 to your computer and use it in GitHub Desktop.

Select an option

Save Quby/1565434 to your computer and use it in GitHub Desktop.

Revisions

  1. Quby created this gist Jan 5, 2012.
    22 changes: 22 additions & 0 deletions ex1
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,22 @@
    #include "./../deps/libuv/include/uv.h"
    #include <stdio.h>

    int msg;

    void mkdir_cb (uv_fs_t* req) {
    int* msg = req->data;
    printf("send(%d)\n", *msg);
    }

    void main () {
    uv_loop_t* loop = uv_loop_new();

    uv_fs_t req;
    msg = 432;
    req.data = &msg;

    const char* path = "test";

    uv_fs_mkdir(loop, &req, path, 0777, mkdir_cb);
    uv_run(loop);
    }
    32 changes: 32 additions & 0 deletions ex2
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,32 @@
    #include "./../deps/libuv/include/uv.h"
    #include <stdio.h>

    //gcc -pthread ../deps/libuv/bin/*.o ex2.c -lrt -ldl -lm -o ex2

    uv_loop_t* loop;

    void timer_cb1 (uv_timer_t* timer, int status) {
    printf("1\n", status);
    uv_timer_stop(timer);
    uv_unref(loop);
    }

    void timer_cb2 (uv_timer_t* timer, int status) {
    printf("2\n", status);
    uv_timer_stop(timer);
    uv_unref(loop);
    }

    void main () {
    loop = uv_default_loop();

    uv_timer_t timer1;
    uv_timer_init(loop, &timer1);
    uv_timer_start(&timer1, (uv_timer_cb) &timer_cb1, 1000, 1000);

    uv_timer_t timer2;
    uv_timer_init(loop, &timer2);
    uv_timer_start(&timer2, (uv_timer_cb) &timer_cb1, 500, 1000);

    uv_run(loop);
    }