Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#include <uv.h>
#include <stdlib.h>
// Thanks learnuv.
#define CHECK(r, msg) if (r) { \
sprintf("%s: [%s(%d): %s]\n", msg, uv_err_name((r)), (int) r, uv_strerror((r))); \
exit(1); \
}
void we_made_it_to_the_poller(uv_poll_t* hdl, int status, int events)
{
CHECK(status, "uv_poll_start");
sprintf("%d", events);
}
int main(void)
{
int r = 0, fd;
// Allocate the loop.
uv_loop_t* loop = uv_default_loop();
uv_poll_t poll_hdl;
fd = open("./test_file_polling_libuv.c", O_RDONLY);
r = uv_poll_init(loop, &poll_hdl, fd);
CHECK(r, "uv_poll_init");
uv_poll_start(&poll_hdl, UV_READABLE, we_made_it_to_the_poller);
uv_run(loop, UV_RUN_DEFAULT);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.