-
-
Save huruji/a1db8fef386da3b2e757c6df6988e648 to your computer and use it in GitHub Desktop.
libuv example, timers and mkdir
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment