#include #include #include #include #include int main(void) { struct timespec ts; #define NR_EVENTS 1024 io_context_t ctx = 0UL; struct iocb iocb; struct iocb *iocbs[1] = { &iocb }; struct io_event event; char buf[256]; int fds[2]; long ret; ret = io_setup(NR_EVENTS, &ctx); if (ret) { printf("io_setup() failed: %s\n", strerror(-ret)); return 1; } ret = pipe(fds); if (ret) { perror("pipe() failed:"); return 1; } io_prep_pread(&iocb, fds[0], buf, sizeof(buf), 0LL); ret = io_submit(ctx, 1, iocbs); if (ret <= 0) { printf("io_submit() failed: %s\n", strerror(-ret)); return 1; } #if 0 ts.tv_sec = 1; ts.tv_nsec = 0; ret = io_getevents(ctx, 1, 1, &event, &ts); printf("io_getevents() = %ld: %s\n", ret, strerror(ret < 0 ? -ret : 0)); #endif ret = io_cancel(ctx, &iocb, &event); if (ret == -EINPROGRESS) printf("io_cancel() success: EINPROGRESS\n"); else if (ret < 0) { printf("io_cancel() failed: %s\n", strerror(-ret)); return 1; } if (!ret) { printf("io_cancel() = 0 - success!\n"); printf("event.res = %ld\n", (long)event.res); printf("event.res2 = %ld\n", (long)event.res2); return 0; } ts.tv_sec = 1; ts.tv_nsec = 0; ret = io_getevents(ctx, 1, 1, &event, &ts); if (ret <= 0) { printf("io_getevents() = %ld: %s\n", ret, strerror(-ret)); return 1; } if (ret != 1) { printf("io_getevents() = %ld: error != 1!\n", ret); return 1; } printf("event.res = %ld : %s\n", (long)event.res, (long)event.res < 0 ? strerror(-(long)event.res) : "success!"); printf("event.res2 = %ld\n", (long)event.res2); if (event.res == -EINTR) printf("Test passed!\n"); else printf("Test failed! Unexpected result in event.res (should be %d).\n", -EINTR); return 0; }