-
-
Save Quby/1565434 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
In the last libuv version the last line must be:
uv_run(loop, UV_RUN_DEFAULT);
The line 29 is calling the same callback function. It should be
timer_cb2
.To compile on Windows with MinGW:
gcc ex2.c -o ex2 -llibuv