polyphony 0.85 → 0.86
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/Gemfile.lock +1 -1
- data/ext/polyphony/io_extensions.c +2 -3
- data/lib/polyphony/version.rb +1 -1
- data/polyphony.gemspec +1 -1
- data/test/test_backend.rb +1 -1
- data/test/test_signal.rb +3 -3
- data/vendor/liburing/.github/pull_request_template.md +86 -0
- data/vendor/liburing/.github/workflows/build.yml +85 -0
- data/vendor/liburing/.github/workflows/shellcheck.yml +20 -0
- data/vendor/liburing/.gitignore +149 -0
- data/vendor/liburing/COPYING +502 -0
- data/vendor/liburing/COPYING.GPL +339 -0
- data/vendor/liburing/LICENSE +7 -0
- data/vendor/liburing/Makefile +82 -0
- data/vendor/liburing/Makefile.common +5 -0
- data/vendor/liburing/Makefile.quiet +11 -0
- data/vendor/liburing/README +46 -0
- data/vendor/liburing/configure +486 -0
- data/vendor/liburing/debian/README.Debian +7 -0
- data/vendor/liburing/debian/changelog +27 -0
- data/vendor/liburing/debian/compat +1 -0
- data/vendor/liburing/debian/control +48 -0
- data/vendor/liburing/debian/copyright +49 -0
- data/vendor/liburing/debian/liburing-dev.install +4 -0
- data/vendor/liburing/debian/liburing-dev.manpages +6 -0
- data/vendor/liburing/debian/liburing1-udeb.install +1 -0
- data/vendor/liburing/debian/liburing1.install +1 -0
- data/vendor/liburing/debian/liburing1.symbols +32 -0
- data/vendor/liburing/debian/patches/series +1 -0
- data/vendor/liburing/debian/rules +81 -0
- data/vendor/liburing/debian/source/format +1 -0
- data/vendor/liburing/debian/source/local-options +2 -0
- data/vendor/liburing/debian/source/options +1 -0
- data/vendor/liburing/debian/watch +3 -0
- data/vendor/liburing/examples/Makefile +38 -0
- data/vendor/liburing/examples/io_uring-cp.c +282 -0
- data/vendor/liburing/examples/io_uring-test.c +112 -0
- data/vendor/liburing/examples/link-cp.c +193 -0
- data/vendor/liburing/examples/ucontext-cp.c +273 -0
- data/vendor/liburing/liburing.pc.in +12 -0
- data/vendor/liburing/liburing.spec +66 -0
- data/vendor/liburing/make-debs.sh +53 -0
- data/vendor/liburing/man/io_uring.7 +754 -0
- data/vendor/liburing/man/io_uring_cq_advance.3 +35 -0
- data/vendor/liburing/man/io_uring_cq_ready.3 +25 -0
- data/vendor/liburing/man/io_uring_cqe_get_data.3 +34 -0
- data/vendor/liburing/man/io_uring_cqe_seen.3 +32 -0
- data/vendor/liburing/man/io_uring_enter.2 +1483 -0
- data/vendor/liburing/man/io_uring_free_probe.3 +24 -0
- data/vendor/liburing/man/io_uring_get_probe.3 +29 -0
- data/vendor/liburing/man/io_uring_get_sqe.3 +38 -0
- data/vendor/liburing/man/io_uring_opcode_supported.3 +29 -0
- data/vendor/liburing/man/io_uring_prep_msg_ring.3 +58 -0
- data/vendor/liburing/man/io_uring_prep_read.3 +50 -0
- data/vendor/liburing/man/io_uring_prep_read_fixed.3 +54 -0
- data/vendor/liburing/man/io_uring_prep_readv.3 +51 -0
- data/vendor/liburing/man/io_uring_prep_readv2.3 +79 -0
- data/vendor/liburing/man/io_uring_prep_write.3 +50 -0
- data/vendor/liburing/man/io_uring_prep_write_fixed.3 +54 -0
- data/vendor/liburing/man/io_uring_prep_writev.3 +51 -0
- data/vendor/liburing/man/io_uring_prep_writev2.3 +78 -0
- data/vendor/liburing/man/io_uring_queue_exit.3 +27 -0
- data/vendor/liburing/man/io_uring_queue_init.3 +44 -0
- data/vendor/liburing/man/io_uring_register.2 +688 -0
- data/vendor/liburing/man/io_uring_register_buffers.3 +41 -0
- data/vendor/liburing/man/io_uring_register_files.3 +35 -0
- data/vendor/liburing/man/io_uring_setup.2 +534 -0
- data/vendor/liburing/man/io_uring_sq_ready.3 +25 -0
- data/vendor/liburing/man/io_uring_sq_space_left.3 +25 -0
- data/vendor/liburing/man/io_uring_sqe_set_data.3 +30 -0
- data/vendor/liburing/man/io_uring_sqe_set_flags.3 +60 -0
- data/vendor/liburing/man/io_uring_sqring_wait.3 +30 -0
- data/vendor/liburing/man/io_uring_submit.3 +29 -0
- data/vendor/liburing/man/io_uring_submit_and_wait.3 +34 -0
- data/vendor/liburing/man/io_uring_submit_and_wait_timeout.3 +49 -0
- data/vendor/liburing/man/io_uring_unregister_buffers.3 +26 -0
- data/vendor/liburing/man/io_uring_unregister_files.3 +26 -0
- data/vendor/liburing/man/io_uring_wait_cqe.3 +33 -0
- data/vendor/liburing/man/io_uring_wait_cqe_nr.3 +36 -0
- data/vendor/liburing/man/io_uring_wait_cqe_timeout.3 +39 -0
- data/vendor/liburing/man/io_uring_wait_cqes.3 +46 -0
- data/vendor/liburing/src/Makefile +89 -0
- data/vendor/liburing/src/arch/aarch64/syscall.h +95 -0
- data/vendor/liburing/src/arch/generic/lib.h +21 -0
- data/vendor/liburing/src/arch/generic/syscall.h +87 -0
- data/vendor/liburing/src/arch/syscall-defs.h +67 -0
- data/vendor/liburing/src/arch/x86/lib.h +32 -0
- data/vendor/liburing/src/arch/x86/syscall.h +160 -0
- data/vendor/liburing/src/include/liburing/barrier.h +81 -0
- data/vendor/liburing/src/include/liburing/io_uring.h +442 -0
- data/vendor/liburing/src/include/liburing.h +921 -0
- data/vendor/liburing/src/int_flags.h +8 -0
- data/vendor/liburing/src/lib.h +57 -0
- data/vendor/liburing/src/liburing.map +53 -0
- data/vendor/liburing/src/nolibc.c +48 -0
- data/vendor/liburing/src/queue.c +403 -0
- data/vendor/liburing/src/register.c +293 -0
- data/vendor/liburing/src/setup.c +332 -0
- data/vendor/liburing/src/syscall.c +47 -0
- data/vendor/liburing/src/syscall.h +103 -0
- data/vendor/liburing/test/232c93d07b74-test.c +306 -0
- data/vendor/liburing/test/35fa71a030ca-test.c +329 -0
- data/vendor/liburing/test/500f9fbadef8-test.c +89 -0
- data/vendor/liburing/test/7ad0e4b2f83c-test.c +93 -0
- data/vendor/liburing/test/8a9973408177-test.c +106 -0
- data/vendor/liburing/test/917257daa0fe-test.c +53 -0
- data/vendor/liburing/test/Makefile +244 -0
- data/vendor/liburing/test/a0908ae19763-test.c +58 -0
- data/vendor/liburing/test/a4c0b3decb33-test.c +180 -0
- data/vendor/liburing/test/accept-link.c +254 -0
- data/vendor/liburing/test/accept-reuse.c +164 -0
- data/vendor/liburing/test/accept-test.c +79 -0
- data/vendor/liburing/test/accept.c +477 -0
- data/vendor/liburing/test/across-fork.c +283 -0
- data/vendor/liburing/test/b19062a56726-test.c +53 -0
- data/vendor/liburing/test/b5837bd5311d-test.c +77 -0
- data/vendor/liburing/test/ce593a6c480a-test.c +136 -0
- data/vendor/liburing/test/close-opath.c +122 -0
- data/vendor/liburing/test/config +10 -0
- data/vendor/liburing/test/connect.c +398 -0
- data/vendor/liburing/test/cq-full.c +96 -0
- data/vendor/liburing/test/cq-overflow.c +294 -0
- data/vendor/liburing/test/cq-peek-batch.c +102 -0
- data/vendor/liburing/test/cq-ready.c +94 -0
- data/vendor/liburing/test/cq-size.c +64 -0
- data/vendor/liburing/test/d4ae271dfaae-test.c +96 -0
- data/vendor/liburing/test/d77a67ed5f27-test.c +65 -0
- data/vendor/liburing/test/defer.c +307 -0
- data/vendor/liburing/test/double-poll-crash.c +185 -0
- data/vendor/liburing/test/drop-submit.c +92 -0
- data/vendor/liburing/test/eeed8b54e0df-test.c +114 -0
- data/vendor/liburing/test/empty-eownerdead.c +45 -0
- data/vendor/liburing/test/eventfd-disable.c +151 -0
- data/vendor/liburing/test/eventfd-reg.c +76 -0
- data/vendor/liburing/test/eventfd-ring.c +97 -0
- data/vendor/liburing/test/eventfd.c +112 -0
- data/vendor/liburing/test/exec-target.c +6 -0
- data/vendor/liburing/test/exit-no-cleanup.c +117 -0
- data/vendor/liburing/test/fadvise.c +202 -0
- data/vendor/liburing/test/fallocate.c +249 -0
- data/vendor/liburing/test/fc2a85cb02ef-test.c +131 -0
- data/vendor/liburing/test/file-register.c +858 -0
- data/vendor/liburing/test/file-update.c +173 -0
- data/vendor/liburing/test/file-verify.c +629 -0
- data/vendor/liburing/test/files-exit-hang-poll.c +128 -0
- data/vendor/liburing/test/files-exit-hang-timeout.c +134 -0
- data/vendor/liburing/test/fixed-link.c +90 -0
- data/vendor/liburing/test/fpos.c +252 -0
- data/vendor/liburing/test/fsync.c +224 -0
- data/vendor/liburing/test/hardlink.c +136 -0
- data/vendor/liburing/test/helpers.c +135 -0
- data/vendor/liburing/test/helpers.h +67 -0
- data/vendor/liburing/test/io-cancel.c +550 -0
- data/vendor/liburing/test/io_uring_enter.c +296 -0
- data/vendor/liburing/test/io_uring_register.c +676 -0
- data/vendor/liburing/test/io_uring_setup.c +192 -0
- data/vendor/liburing/test/iopoll.c +372 -0
- data/vendor/liburing/test/lfs-openat-write.c +119 -0
- data/vendor/liburing/test/lfs-openat.c +275 -0
- data/vendor/liburing/test/link-timeout.c +1107 -0
- data/vendor/liburing/test/link.c +496 -0
- data/vendor/liburing/test/link_drain.c +229 -0
- data/vendor/liburing/test/madvise.c +195 -0
- data/vendor/liburing/test/mkdir.c +108 -0
- data/vendor/liburing/test/msg-ring.c +234 -0
- data/vendor/liburing/test/multicqes_drain.c +387 -0
- data/vendor/liburing/test/nop-all-sizes.c +99 -0
- data/vendor/liburing/test/nop.c +115 -0
- data/vendor/liburing/test/open-close.c +261 -0
- data/vendor/liburing/test/openat2.c +308 -0
- data/vendor/liburing/test/personality.c +204 -0
- data/vendor/liburing/test/pipe-eof.c +83 -0
- data/vendor/liburing/test/pipe-reuse.c +105 -0
- data/vendor/liburing/test/poll-cancel-ton.c +135 -0
- data/vendor/liburing/test/poll-cancel.c +228 -0
- data/vendor/liburing/test/poll-link.c +230 -0
- data/vendor/liburing/test/poll-many.c +208 -0
- data/vendor/liburing/test/poll-mshot-update.c +273 -0
- data/vendor/liburing/test/poll-ring.c +48 -0
- data/vendor/liburing/test/poll-v-poll.c +353 -0
- data/vendor/liburing/test/poll.c +109 -0
- data/vendor/liburing/test/pollfree.c +426 -0
- data/vendor/liburing/test/probe.c +135 -0
- data/vendor/liburing/test/read-write.c +876 -0
- data/vendor/liburing/test/register-restrictions.c +633 -0
- data/vendor/liburing/test/rename.c +135 -0
- data/vendor/liburing/test/ring-leak.c +173 -0
- data/vendor/liburing/test/ring-leak2.c +249 -0
- data/vendor/liburing/test/rsrc_tags.c +449 -0
- data/vendor/liburing/test/runtests-loop.sh +16 -0
- data/vendor/liburing/test/runtests.sh +170 -0
- data/vendor/liburing/test/rw_merge_test.c +97 -0
- data/vendor/liburing/test/self.c +91 -0
- data/vendor/liburing/test/send_recv.c +286 -0
- data/vendor/liburing/test/send_recvmsg.c +345 -0
- data/vendor/liburing/test/sendmsg_fs_cve.c +200 -0
- data/vendor/liburing/test/shared-wq.c +84 -0
- data/vendor/liburing/test/short-read.c +75 -0
- data/vendor/liburing/test/shutdown.c +165 -0
- data/vendor/liburing/test/sigfd-deadlock.c +74 -0
- data/vendor/liburing/test/skip-cqe.c +429 -0
- data/vendor/liburing/test/socket-rw-eagain.c +158 -0
- data/vendor/liburing/test/socket-rw-offset.c +157 -0
- data/vendor/liburing/test/socket-rw.c +145 -0
- data/vendor/liburing/test/splice.c +512 -0
- data/vendor/liburing/test/sq-full-cpp.cc +45 -0
- data/vendor/liburing/test/sq-full.c +45 -0
- data/vendor/liburing/test/sq-poll-dup.c +204 -0
- data/vendor/liburing/test/sq-poll-kthread.c +169 -0
- data/vendor/liburing/test/sq-poll-share.c +137 -0
- data/vendor/liburing/test/sq-space_left.c +159 -0
- data/vendor/liburing/test/sqpoll-cancel-hang.c +157 -0
- data/vendor/liburing/test/sqpoll-disable-exit.c +196 -0
- data/vendor/liburing/test/sqpoll-exit-hang.c +78 -0
- data/vendor/liburing/test/sqpoll-sleep.c +69 -0
- data/vendor/liburing/test/statx.c +172 -0
- data/vendor/liburing/test/stdout.c +232 -0
- data/vendor/liburing/test/submit-link-fail.c +154 -0
- data/vendor/liburing/test/submit-reuse.c +239 -0
- data/vendor/liburing/test/symlink.c +116 -0
- data/vendor/liburing/test/teardowns.c +58 -0
- data/vendor/liburing/test/thread-exit.c +143 -0
- data/vendor/liburing/test/timeout-new.c +252 -0
- data/vendor/liburing/test/timeout-overflow.c +204 -0
- data/vendor/liburing/test/timeout.c +1523 -0
- data/vendor/liburing/test/unlink.c +112 -0
- data/vendor/liburing/test/wakeup-hang.c +162 -0
- metadata +223 -2
@@ -0,0 +1,97 @@
|
|
1
|
+
/* SPDX-License-Identifier: MIT */
|
2
|
+
/*
|
3
|
+
* Regression test for incorrect async_list io_should_merge() logic
|
4
|
+
* Bug was fixed in 5.5 by (commit: 561fb04 io_uring: replace workqueue usage with io-wq")
|
5
|
+
* Affects 5.4 lts branch, at least 5.4.106 is affected.
|
6
|
+
*/
|
7
|
+
#include <stdio.h>
|
8
|
+
#include <errno.h>
|
9
|
+
#include <sys/socket.h>
|
10
|
+
#include <sys/un.h>
|
11
|
+
#include <assert.h>
|
12
|
+
#include <fcntl.h>
|
13
|
+
#include <unistd.h>
|
14
|
+
|
15
|
+
#include "liburing.h"
|
16
|
+
#include "helpers.h"
|
17
|
+
|
18
|
+
int main(int argc, char *argv[])
|
19
|
+
{
|
20
|
+
struct io_uring_sqe *sqe;
|
21
|
+
struct io_uring_cqe *cqe;
|
22
|
+
struct io_uring ring;
|
23
|
+
int ret, fd, pipe1[2];
|
24
|
+
char buf[4096];
|
25
|
+
struct iovec vec = {
|
26
|
+
.iov_base = buf,
|
27
|
+
.iov_len = sizeof(buf)
|
28
|
+
};
|
29
|
+
struct __kernel_timespec ts = {.tv_sec = 3, .tv_nsec = 0};
|
30
|
+
|
31
|
+
if (argc > 1)
|
32
|
+
return 0;
|
33
|
+
|
34
|
+
ret = pipe(pipe1);
|
35
|
+
assert(!ret);
|
36
|
+
|
37
|
+
fd = open("testfile", O_RDWR | O_CREAT, 0644);
|
38
|
+
assert(ret >= 0);
|
39
|
+
ret = ftruncate(fd, 4096);
|
40
|
+
assert(!ret);
|
41
|
+
|
42
|
+
ret = t_create_ring(4, &ring, 0);
|
43
|
+
if (ret == T_SETUP_SKIP)
|
44
|
+
return 0;
|
45
|
+
else if (ret < 0)
|
46
|
+
return 1;
|
47
|
+
|
48
|
+
/* REQ1 */
|
49
|
+
sqe = io_uring_get_sqe(&ring);
|
50
|
+
io_uring_prep_readv(sqe, pipe1[0], &vec, 1, 0);
|
51
|
+
sqe->user_data = 1;
|
52
|
+
|
53
|
+
/* REQ2 */
|
54
|
+
sqe = io_uring_get_sqe(&ring);
|
55
|
+
io_uring_prep_readv(sqe, fd, &vec, 1, 4096);
|
56
|
+
sqe->user_data = 2;
|
57
|
+
|
58
|
+
ret = io_uring_submit(&ring);
|
59
|
+
assert(ret == 2);
|
60
|
+
|
61
|
+
ret = io_uring_wait_cqe(&ring, &cqe);
|
62
|
+
assert(!ret);
|
63
|
+
assert(cqe->res == 0);
|
64
|
+
assert(cqe->user_data == 2);
|
65
|
+
io_uring_cqe_seen(&ring, cqe);
|
66
|
+
|
67
|
+
/*
|
68
|
+
* REQ3
|
69
|
+
* Prepare request adjacent to previous one, so merge logic may want to
|
70
|
+
* link it to previous request, but because of a bug in merge logic
|
71
|
+
* it may be merged with <REQ1> request
|
72
|
+
*/
|
73
|
+
sqe = io_uring_get_sqe(&ring);
|
74
|
+
io_uring_prep_readv(sqe, fd, &vec, 1, 2048);
|
75
|
+
sqe->user_data = 3;
|
76
|
+
|
77
|
+
ret = io_uring_submit(&ring);
|
78
|
+
assert(ret == 1);
|
79
|
+
|
80
|
+
/*
|
81
|
+
* Read may stuck because of bug there request was be incorrecly
|
82
|
+
* merged with <REQ1> request
|
83
|
+
*/
|
84
|
+
ret = io_uring_wait_cqe_timeout(&ring, &cqe, &ts);
|
85
|
+
if (ret == -ETIME) {
|
86
|
+
printf("TEST_FAIL: readv req3 stuck\n");
|
87
|
+
return 1;
|
88
|
+
}
|
89
|
+
assert(!ret);
|
90
|
+
|
91
|
+
assert(cqe->res == 2048);
|
92
|
+
assert(cqe->user_data == 3);
|
93
|
+
|
94
|
+
io_uring_cqe_seen(&ring, cqe);
|
95
|
+
io_uring_queue_exit(&ring);
|
96
|
+
return 0;
|
97
|
+
}
|
@@ -0,0 +1,91 @@
|
|
1
|
+
/* SPDX-License-Identifier: MIT */
|
2
|
+
/*
|
3
|
+
* Description: test that pathname resolution works from async context when
|
4
|
+
* using /proc/self/ which should be the original submitting task, not the
|
5
|
+
* async worker.
|
6
|
+
*
|
7
|
+
*/
|
8
|
+
#include <errno.h>
|
9
|
+
#include <stdio.h>
|
10
|
+
#include <unistd.h>
|
11
|
+
#include <stdlib.h>
|
12
|
+
#include <string.h>
|
13
|
+
#include <fcntl.h>
|
14
|
+
|
15
|
+
#include "liburing.h"
|
16
|
+
|
17
|
+
static int io_openat2(struct io_uring *ring, const char *path, int dfd)
|
18
|
+
{
|
19
|
+
struct io_uring_cqe *cqe;
|
20
|
+
struct io_uring_sqe *sqe;
|
21
|
+
struct open_how how;
|
22
|
+
int ret;
|
23
|
+
|
24
|
+
sqe = io_uring_get_sqe(ring);
|
25
|
+
if (!sqe) {
|
26
|
+
fprintf(stderr, "get sqe failed\n");
|
27
|
+
goto err;
|
28
|
+
}
|
29
|
+
memset(&how, 0, sizeof(how));
|
30
|
+
how.flags = O_RDONLY;
|
31
|
+
io_uring_prep_openat2(sqe, dfd, path, &how);
|
32
|
+
|
33
|
+
ret = io_uring_submit(ring);
|
34
|
+
if (ret <= 0) {
|
35
|
+
fprintf(stderr, "sqe submit failed: %d\n", ret);
|
36
|
+
goto err;
|
37
|
+
}
|
38
|
+
|
39
|
+
ret = io_uring_wait_cqe(ring, &cqe);
|
40
|
+
if (ret < 0) {
|
41
|
+
fprintf(stderr, "wait completion %d\n", ret);
|
42
|
+
goto err;
|
43
|
+
}
|
44
|
+
ret = cqe->res;
|
45
|
+
io_uring_cqe_seen(ring, cqe);
|
46
|
+
return ret;
|
47
|
+
err:
|
48
|
+
return -1;
|
49
|
+
}
|
50
|
+
|
51
|
+
int main(int argc, char *argv[])
|
52
|
+
{
|
53
|
+
struct io_uring ring;
|
54
|
+
char buf[64];
|
55
|
+
int ret;
|
56
|
+
|
57
|
+
if (argc > 1)
|
58
|
+
return 0;
|
59
|
+
|
60
|
+
ret = io_uring_queue_init(1, &ring, 0);
|
61
|
+
if (ret) {
|
62
|
+
fprintf(stderr, "ring setup failed\n");
|
63
|
+
return 1;
|
64
|
+
}
|
65
|
+
|
66
|
+
ret = io_openat2(&ring, "/proc/self/comm", -1);
|
67
|
+
if (ret < 0) {
|
68
|
+
if (ret == -EOPNOTSUPP)
|
69
|
+
return 0;
|
70
|
+
if (ret == -EINVAL) {
|
71
|
+
fprintf(stdout, "openat2 not supported, skipping\n");
|
72
|
+
return 0;
|
73
|
+
}
|
74
|
+
fprintf(stderr, "openat2 failed: %s\n", strerror(-ret));
|
75
|
+
return 1;
|
76
|
+
}
|
77
|
+
|
78
|
+
memset(buf, 0, sizeof(buf));
|
79
|
+
ret = read(ret, buf, sizeof(buf));
|
80
|
+
if (ret < 0) {
|
81
|
+
perror("read");
|
82
|
+
return 1;
|
83
|
+
}
|
84
|
+
|
85
|
+
if (strncmp(buf, "self", 4)) {
|
86
|
+
fprintf(stderr, "got comm=<%s>, wanted <self>\n", buf);
|
87
|
+
return 1;
|
88
|
+
}
|
89
|
+
|
90
|
+
return 0;
|
91
|
+
}
|
@@ -0,0 +1,286 @@
|
|
1
|
+
/* SPDX-License-Identifier: MIT */
|
2
|
+
/*
|
3
|
+
* Simple test case showing using send and recv through io_uring
|
4
|
+
*/
|
5
|
+
#include <errno.h>
|
6
|
+
#include <stdio.h>
|
7
|
+
#include <stdlib.h>
|
8
|
+
#include <string.h>
|
9
|
+
#include <unistd.h>
|
10
|
+
#include <arpa/inet.h>
|
11
|
+
#include <sys/types.h>
|
12
|
+
#include <sys/socket.h>
|
13
|
+
#include <pthread.h>
|
14
|
+
|
15
|
+
#include "liburing.h"
|
16
|
+
#include "helpers.h"
|
17
|
+
|
18
|
+
static char str[] = "This is a test of send and recv over io_uring!";
|
19
|
+
|
20
|
+
#define MAX_MSG 128
|
21
|
+
|
22
|
+
#define PORT 10200
|
23
|
+
#define HOST "127.0.0.1"
|
24
|
+
|
25
|
+
static int recv_prep(struct io_uring *ring, struct iovec *iov, int *sock,
|
26
|
+
int registerfiles)
|
27
|
+
{
|
28
|
+
struct sockaddr_in saddr;
|
29
|
+
struct io_uring_sqe *sqe;
|
30
|
+
int sockfd, ret, val, use_fd;
|
31
|
+
|
32
|
+
memset(&saddr, 0, sizeof(saddr));
|
33
|
+
saddr.sin_family = AF_INET;
|
34
|
+
saddr.sin_addr.s_addr = htonl(INADDR_ANY);
|
35
|
+
saddr.sin_port = htons(PORT);
|
36
|
+
|
37
|
+
sockfd = socket(AF_INET, SOCK_DGRAM, 0);
|
38
|
+
if (sockfd < 0) {
|
39
|
+
perror("socket");
|
40
|
+
return 1;
|
41
|
+
}
|
42
|
+
|
43
|
+
val = 1;
|
44
|
+
setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, &val, sizeof(val));
|
45
|
+
|
46
|
+
ret = bind(sockfd, (struct sockaddr *)&saddr, sizeof(saddr));
|
47
|
+
if (ret < 0) {
|
48
|
+
perror("bind");
|
49
|
+
goto err;
|
50
|
+
}
|
51
|
+
|
52
|
+
if (registerfiles) {
|
53
|
+
ret = io_uring_register_files(ring, &sockfd, 1);
|
54
|
+
if (ret) {
|
55
|
+
fprintf(stderr, "file reg failed\n");
|
56
|
+
goto err;
|
57
|
+
}
|
58
|
+
use_fd = 0;
|
59
|
+
} else {
|
60
|
+
use_fd = sockfd;
|
61
|
+
}
|
62
|
+
|
63
|
+
sqe = io_uring_get_sqe(ring);
|
64
|
+
io_uring_prep_recv(sqe, use_fd, iov->iov_base, iov->iov_len, 0);
|
65
|
+
if (registerfiles)
|
66
|
+
sqe->flags |= IOSQE_FIXED_FILE;
|
67
|
+
sqe->user_data = 2;
|
68
|
+
|
69
|
+
ret = io_uring_submit(ring);
|
70
|
+
if (ret <= 0) {
|
71
|
+
fprintf(stderr, "submit failed: %d\n", ret);
|
72
|
+
goto err;
|
73
|
+
}
|
74
|
+
|
75
|
+
*sock = sockfd;
|
76
|
+
return 0;
|
77
|
+
err:
|
78
|
+
close(sockfd);
|
79
|
+
return 1;
|
80
|
+
}
|
81
|
+
|
82
|
+
static int do_recv(struct io_uring *ring, struct iovec *iov)
|
83
|
+
{
|
84
|
+
struct io_uring_cqe *cqe;
|
85
|
+
int ret;
|
86
|
+
|
87
|
+
ret = io_uring_wait_cqe(ring, &cqe);
|
88
|
+
if (ret) {
|
89
|
+
fprintf(stdout, "wait_cqe: %d\n", ret);
|
90
|
+
goto err;
|
91
|
+
}
|
92
|
+
if (cqe->res == -EINVAL) {
|
93
|
+
fprintf(stdout, "recv not supported, skipping\n");
|
94
|
+
return 0;
|
95
|
+
}
|
96
|
+
if (cqe->res < 0) {
|
97
|
+
fprintf(stderr, "failed cqe: %d\n", cqe->res);
|
98
|
+
goto err;
|
99
|
+
}
|
100
|
+
|
101
|
+
if (cqe->res -1 != strlen(str)) {
|
102
|
+
fprintf(stderr, "got wrong length: %d/%d\n", cqe->res,
|
103
|
+
(int) strlen(str) + 1);
|
104
|
+
goto err;
|
105
|
+
}
|
106
|
+
|
107
|
+
if (strcmp(str, iov->iov_base)) {
|
108
|
+
fprintf(stderr, "string mismatch\n");
|
109
|
+
goto err;
|
110
|
+
}
|
111
|
+
|
112
|
+
return 0;
|
113
|
+
err:
|
114
|
+
return 1;
|
115
|
+
}
|
116
|
+
|
117
|
+
struct recv_data {
|
118
|
+
pthread_mutex_t mutex;
|
119
|
+
int use_sqthread;
|
120
|
+
int registerfiles;
|
121
|
+
};
|
122
|
+
|
123
|
+
static void *recv_fn(void *data)
|
124
|
+
{
|
125
|
+
struct recv_data *rd = data;
|
126
|
+
char buf[MAX_MSG + 1];
|
127
|
+
struct iovec iov = {
|
128
|
+
.iov_base = buf,
|
129
|
+
.iov_len = sizeof(buf) - 1,
|
130
|
+
};
|
131
|
+
struct io_uring_params p = { };
|
132
|
+
struct io_uring ring;
|
133
|
+
int ret, sock;
|
134
|
+
|
135
|
+
if (rd->use_sqthread)
|
136
|
+
p.flags = IORING_SETUP_SQPOLL;
|
137
|
+
ret = t_create_ring_params(1, &ring, &p);
|
138
|
+
if (ret == T_SETUP_SKIP) {
|
139
|
+
pthread_mutex_unlock(&rd->mutex);
|
140
|
+
ret = 0;
|
141
|
+
goto err;
|
142
|
+
} else if (ret < 0) {
|
143
|
+
pthread_mutex_unlock(&rd->mutex);
|
144
|
+
goto err;
|
145
|
+
}
|
146
|
+
|
147
|
+
if (rd->use_sqthread && !rd->registerfiles) {
|
148
|
+
if (!(p.features & IORING_FEAT_SQPOLL_NONFIXED)) {
|
149
|
+
fprintf(stdout, "Non-registered SQPOLL not available, skipping\n");
|
150
|
+
pthread_mutex_unlock(&rd->mutex);
|
151
|
+
goto err;
|
152
|
+
}
|
153
|
+
}
|
154
|
+
|
155
|
+
ret = recv_prep(&ring, &iov, &sock, rd->registerfiles);
|
156
|
+
if (ret) {
|
157
|
+
fprintf(stderr, "recv_prep failed: %d\n", ret);
|
158
|
+
goto err;
|
159
|
+
}
|
160
|
+
pthread_mutex_unlock(&rd->mutex);
|
161
|
+
ret = do_recv(&ring, &iov);
|
162
|
+
|
163
|
+
close(sock);
|
164
|
+
io_uring_queue_exit(&ring);
|
165
|
+
err:
|
166
|
+
return (void *)(intptr_t)ret;
|
167
|
+
}
|
168
|
+
|
169
|
+
static int do_send(void)
|
170
|
+
{
|
171
|
+
struct sockaddr_in saddr;
|
172
|
+
struct iovec iov = {
|
173
|
+
.iov_base = str,
|
174
|
+
.iov_len = sizeof(str),
|
175
|
+
};
|
176
|
+
struct io_uring ring;
|
177
|
+
struct io_uring_cqe *cqe;
|
178
|
+
struct io_uring_sqe *sqe;
|
179
|
+
int sockfd, ret;
|
180
|
+
|
181
|
+
ret = io_uring_queue_init(1, &ring, 0);
|
182
|
+
if (ret) {
|
183
|
+
fprintf(stderr, "queue init failed: %d\n", ret);
|
184
|
+
return 1;
|
185
|
+
}
|
186
|
+
|
187
|
+
memset(&saddr, 0, sizeof(saddr));
|
188
|
+
saddr.sin_family = AF_INET;
|
189
|
+
saddr.sin_port = htons(PORT);
|
190
|
+
inet_pton(AF_INET, HOST, &saddr.sin_addr);
|
191
|
+
|
192
|
+
sockfd = socket(AF_INET, SOCK_DGRAM, 0);
|
193
|
+
if (sockfd < 0) {
|
194
|
+
perror("socket");
|
195
|
+
return 1;
|
196
|
+
}
|
197
|
+
|
198
|
+
ret = connect(sockfd, (struct sockaddr *)&saddr, sizeof(saddr));
|
199
|
+
if (ret < 0) {
|
200
|
+
perror("connect");
|
201
|
+
return 1;
|
202
|
+
}
|
203
|
+
|
204
|
+
sqe = io_uring_get_sqe(&ring);
|
205
|
+
io_uring_prep_send(sqe, sockfd, iov.iov_base, iov.iov_len, 0);
|
206
|
+
sqe->user_data = 1;
|
207
|
+
|
208
|
+
ret = io_uring_submit(&ring);
|
209
|
+
if (ret <= 0) {
|
210
|
+
fprintf(stderr, "submit failed: %d\n", ret);
|
211
|
+
goto err;
|
212
|
+
}
|
213
|
+
|
214
|
+
ret = io_uring_wait_cqe(&ring, &cqe);
|
215
|
+
if (cqe->res == -EINVAL) {
|
216
|
+
fprintf(stdout, "send not supported, skipping\n");
|
217
|
+
close(sockfd);
|
218
|
+
return 0;
|
219
|
+
}
|
220
|
+
if (cqe->res != iov.iov_len) {
|
221
|
+
fprintf(stderr, "failed cqe: %d\n", cqe->res);
|
222
|
+
goto err;
|
223
|
+
}
|
224
|
+
|
225
|
+
close(sockfd);
|
226
|
+
return 0;
|
227
|
+
err:
|
228
|
+
close(sockfd);
|
229
|
+
return 1;
|
230
|
+
}
|
231
|
+
|
232
|
+
static int test(int use_sqthread, int regfiles)
|
233
|
+
{
|
234
|
+
pthread_mutexattr_t attr;
|
235
|
+
pthread_t recv_thread;
|
236
|
+
struct recv_data rd;
|
237
|
+
int ret;
|
238
|
+
void *retval;
|
239
|
+
|
240
|
+
pthread_mutexattr_init(&attr);
|
241
|
+
pthread_mutexattr_setpshared(&attr, 1);
|
242
|
+
pthread_mutex_init(&rd.mutex, &attr);
|
243
|
+
pthread_mutex_lock(&rd.mutex);
|
244
|
+
rd.use_sqthread = use_sqthread;
|
245
|
+
rd.registerfiles = regfiles;
|
246
|
+
|
247
|
+
ret = pthread_create(&recv_thread, NULL, recv_fn, &rd);
|
248
|
+
if (ret) {
|
249
|
+
fprintf(stderr, "Thread create failed: %d\n", ret);
|
250
|
+
pthread_mutex_unlock(&rd.mutex);
|
251
|
+
return 1;
|
252
|
+
}
|
253
|
+
|
254
|
+
pthread_mutex_lock(&rd.mutex);
|
255
|
+
do_send();
|
256
|
+
pthread_join(recv_thread, &retval);
|
257
|
+
return (int)(intptr_t)retval;
|
258
|
+
}
|
259
|
+
|
260
|
+
int main(int argc, char *argv[])
|
261
|
+
{
|
262
|
+
int ret;
|
263
|
+
|
264
|
+
if (argc > 1)
|
265
|
+
return 0;
|
266
|
+
|
267
|
+
ret = test(0, 0);
|
268
|
+
if (ret) {
|
269
|
+
fprintf(stderr, "test sqthread=0 failed\n");
|
270
|
+
return ret;
|
271
|
+
}
|
272
|
+
|
273
|
+
ret = test(1, 1);
|
274
|
+
if (ret) {
|
275
|
+
fprintf(stderr, "test sqthread=1 reg=1 failed\n");
|
276
|
+
return ret;
|
277
|
+
}
|
278
|
+
|
279
|
+
ret = test(1, 0);
|
280
|
+
if (ret) {
|
281
|
+
fprintf(stderr, "test sqthread=1 reg=0 failed\n");
|
282
|
+
return ret;
|
283
|
+
}
|
284
|
+
|
285
|
+
return 0;
|
286
|
+
}
|