Skip to content

Instantly share code, notes, and snippets.

@jalcine
Last active August 29, 2015 14:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jalcine/b8b61d5521b15d208243 to your computer and use it in GitHub Desktop.
Save jalcine/b8b61d5521b15d208243 to your computer and use it in GitHub Desktop.
#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