Created
December 6, 2015 04:04
-
-
Save evanlucas/8db596602f2bb693b541 to your computer and use it in GitHub Desktop.
watch_dir.c
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 "uv.h" | |
#include <unistd.h> | |
#include <stdio.h> | |
#include <stdlib.h> | |
static uv_fs_event_t fs_event; | |
static uv_timer_t timer; | |
#define ASSERT(expr) \ | |
do { \ | |
if (!(expr)) { \ | |
fprintf(stderr, \ | |
"Assertion failed in %s on line %d: %s\n", \ | |
__FILE__, \ | |
__LINE__, \ | |
#expr); \ | |
abort(); \ | |
} \ | |
} while (0) | |
static void cb(uv_fs_event_t* handle, const char* fn, int events, int status) { | |
printf("cb filename: %s\n", fn); | |
ASSERT(events == UV_CHANGE || UV_RENAME); | |
ASSERT(handle = &fs_event); | |
} | |
static void timer_cb(uv_timer_t* handle) { | |
printf("timer cb...\n"); | |
} | |
void watchdir() { | |
printf("watching...\n"); | |
uv_loop_t* loop = uv_default_loop(); | |
int r; | |
r = uv_fs_event_init(loop, &fs_event); | |
ASSERT(r == 0); | |
r = uv_fs_event_start(&fs_event, cb, "watch_dir", 0); | |
ASSERT(r == 0); | |
r = uv_timer_init(loop, &timer); | |
ASSERT(r == 0); | |
r = uv_timer_start(&timer, timer_cb, 100, 0); | |
ASSERT(r == 0); | |
uv_run(loop, UV_RUN_DEFAULT); | |
} | |
int main() { | |
watchdir(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment