Skip to content

Instantly share code, notes, and snippets.

@kkaefer kkaefer/main.cpp Secret
Created Aug 29, 2014

Embed
What would you like to do?
cancel fs req
#include <uv.h>
#include <cstdio>
#include <cstdlib>
void file_opened(uv_fs_t *req) {
if (req->result < 0) {
fprintf(stderr, "open error: %ld %s\n", req->result, uv_strerror(int(req->result)));
} else {
fprintf(stderr, "opening succeeded!\n");
}
}
int main() {
uv_loop_t *loop = (uv_loop_t *)malloc(sizeof(uv_loop_t));
uv_loop_init(loop);
uv_fs_t *req = (uv_fs_t *)malloc(sizeof(uv_fs_t));
uv_fs_open(loop, req, "main.cpp", O_RDONLY, S_IRUSR, file_opened);
int err = uv_cancel((uv_req_t *)req);
if (err < 0) {
fprintf(stderr, "cancel error: %d %s\n", err, uv_strerror(err));
}
uv_run(loop, UV_RUN_DEFAULT);
free(req);
uv_loop_close(loop);
free(loop);
}
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.