-
-
Save kkaefer/8148fd8d0b8c10aeb64b to your computer and use it in GitHub Desktop.
cancel fs req
This file contains 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 <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