polyphony 0.94 → 0.95
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/test.yml +2 -2
- data/.gitignore +3 -3
- data/CHANGELOG.md +14 -0
- data/docs/api-reference/fiber.md +2 -2
- data/docs/api-reference/object.md +3 -3
- data/docs/main-concepts/exception-handling.md +2 -2
- data/ext/polyphony/backend_common.c +3 -3
- data/ext/polyphony/backend_io_uring.c +18 -16
- data/ext/polyphony/event.c +1 -1
- data/ext/polyphony/extconf.rb +5 -3
- data/ext/polyphony/fiber.c +5 -13
- data/ext/polyphony/io_extensions.c +1 -1
- data/ext/polyphony/pipe.c +1 -1
- data/ext/polyphony/polyphony.c +1 -1
- data/ext/polyphony/polyphony_ext.c +1 -1
- data/ext/polyphony/queue.c +1 -1
- data/ext/polyphony/ring_buffer.c +1 -0
- data/ext/polyphony/socket_extensions.c +1 -1
- data/ext/polyphony/thread.c +1 -1
- data/lib/polyphony/extensions/enumerator.rb +16 -0
- data/lib/polyphony/extensions/socket.rb +2 -0
- data/lib/polyphony/extensions.rb +1 -0
- data/lib/polyphony/version.rb +1 -1
- data/polyphony.gemspec +2 -2
- data/test/test_backend.rb +5 -1
- data/test/test_enumerator.rb +46 -0
- data/test/test_io.rb +241 -216
- data/test/test_socket.rb +1 -1
- data/test/test_thread_pool.rb +3 -3
- data/vendor/liburing/.github/workflows/build.yml +51 -5
- data/vendor/liburing/.github/workflows/shellcheck.yml +1 -1
- data/vendor/liburing/.gitignore +6 -123
- data/vendor/liburing/CHANGELOG +35 -0
- data/vendor/liburing/CITATION.cff +11 -0
- data/vendor/liburing/LICENSE +16 -3
- data/vendor/liburing/Makefile +3 -1
- data/vendor/liburing/Makefile.common +1 -0
- data/vendor/liburing/README +14 -2
- data/vendor/liburing/SECURITY.md +6 -0
- data/vendor/liburing/configure +16 -15
- data/vendor/liburing/examples/Makefile +4 -1
- data/vendor/liburing/examples/io_uring-udp.c +395 -0
- data/vendor/liburing/examples/poll-bench.c +101 -0
- data/vendor/liburing/examples/send-zerocopy.c +339 -0
- data/vendor/liburing/liburing.spec +1 -1
- data/vendor/liburing/man/io_uring.7 +38 -11
- data/vendor/liburing/man/io_uring_buf_ring_add.3 +53 -0
- data/vendor/liburing/man/io_uring_buf_ring_advance.3 +31 -0
- data/vendor/liburing/man/io_uring_buf_ring_cq_advance.3 +41 -0
- data/vendor/liburing/man/io_uring_buf_ring_init.3 +30 -0
- data/vendor/liburing/man/io_uring_buf_ring_mask.3 +27 -0
- data/vendor/liburing/man/io_uring_cq_advance.3 +29 -15
- data/vendor/liburing/man/io_uring_cq_has_overflow.3 +25 -0
- data/vendor/liburing/man/io_uring_cq_ready.3 +9 -8
- data/vendor/liburing/man/io_uring_cqe_get_data.3 +32 -13
- data/vendor/liburing/man/io_uring_cqe_get_data64.3 +1 -0
- data/vendor/liburing/man/io_uring_cqe_seen.3 +22 -12
- data/vendor/liburing/man/io_uring_enter.2 +249 -32
- data/vendor/liburing/man/io_uring_enter2.2 +1 -0
- data/vendor/liburing/man/io_uring_free_probe.3 +11 -8
- data/vendor/liburing/man/io_uring_get_events.3 +33 -0
- data/vendor/liburing/man/io_uring_get_probe.3 +9 -8
- data/vendor/liburing/man/io_uring_get_sqe.3 +29 -10
- data/vendor/liburing/man/io_uring_opcode_supported.3 +11 -10
- data/vendor/liburing/man/io_uring_peek_cqe.3 +38 -0
- data/vendor/liburing/man/io_uring_prep_accept.3 +197 -0
- data/vendor/liburing/man/io_uring_prep_accept_direct.3 +1 -0
- data/vendor/liburing/man/io_uring_prep_cancel.3 +118 -0
- data/vendor/liburing/man/io_uring_prep_cancel64.3 +1 -0
- data/vendor/liburing/man/io_uring_prep_close.3 +59 -0
- data/vendor/liburing/man/io_uring_prep_close_direct.3 +1 -0
- data/vendor/liburing/man/io_uring_prep_connect.3 +66 -0
- data/vendor/liburing/man/io_uring_prep_fadvise.3 +59 -0
- data/vendor/liburing/man/io_uring_prep_fallocate.3 +59 -0
- data/vendor/liburing/man/io_uring_prep_files_update.3 +92 -0
- data/vendor/liburing/man/io_uring_prep_fsync.3 +70 -0
- data/vendor/liburing/man/io_uring_prep_link.3 +1 -0
- data/vendor/liburing/man/io_uring_prep_linkat.3 +91 -0
- data/vendor/liburing/man/io_uring_prep_madvise.3 +56 -0
- data/vendor/liburing/man/io_uring_prep_mkdir.3 +1 -0
- data/vendor/liburing/man/io_uring_prep_mkdirat.3 +83 -0
- data/vendor/liburing/man/io_uring_prep_msg_ring.3 +39 -25
- data/vendor/liburing/man/io_uring_prep_multishot_accept.3 +1 -0
- data/vendor/liburing/man/io_uring_prep_multishot_accept_direct.3 +1 -0
- data/vendor/liburing/man/io_uring_prep_nop.3 +28 -0
- data/vendor/liburing/man/io_uring_prep_openat.3 +117 -0
- data/vendor/liburing/man/io_uring_prep_openat2.3 +117 -0
- data/vendor/liburing/man/io_uring_prep_openat2_direct.3 +1 -0
- data/vendor/liburing/man/io_uring_prep_openat_direct.3 +1 -0
- data/vendor/liburing/man/io_uring_prep_poll_add.3 +72 -0
- data/vendor/liburing/man/io_uring_prep_poll_multishot.3 +1 -0
- data/vendor/liburing/man/io_uring_prep_poll_remove.3 +55 -0
- data/vendor/liburing/man/io_uring_prep_poll_update.3 +89 -0
- data/vendor/liburing/man/io_uring_prep_provide_buffers.3 +131 -0
- data/vendor/liburing/man/io_uring_prep_read.3 +33 -14
- data/vendor/liburing/man/io_uring_prep_read_fixed.3 +39 -21
- data/vendor/liburing/man/io_uring_prep_readv.3 +49 -15
- data/vendor/liburing/man/io_uring_prep_readv2.3 +49 -17
- data/vendor/liburing/man/io_uring_prep_recv.3 +105 -0
- data/vendor/liburing/man/io_uring_prep_recv_multishot.3 +1 -0
- data/vendor/liburing/man/io_uring_prep_recvmsg.3 +124 -0
- data/vendor/liburing/man/io_uring_prep_recvmsg_multishot.3 +1 -0
- data/vendor/liburing/man/io_uring_prep_remove_buffers.3 +52 -0
- data/vendor/liburing/man/io_uring_prep_rename.3 +1 -0
- data/vendor/liburing/man/io_uring_prep_renameat.3 +96 -0
- data/vendor/liburing/man/io_uring_prep_send.3 +57 -0
- data/vendor/liburing/man/io_uring_prep_send_zc.3 +64 -0
- data/vendor/liburing/man/io_uring_prep_sendmsg.3 +69 -0
- data/vendor/liburing/man/io_uring_prep_shutdown.3 +53 -0
- data/vendor/liburing/man/io_uring_prep_socket.3 +118 -0
- data/vendor/liburing/man/io_uring_prep_socket_direct.3 +1 -0
- data/vendor/liburing/man/io_uring_prep_socket_direct_alloc.3 +1 -0
- data/vendor/liburing/man/io_uring_prep_splice.3 +80 -0
- data/vendor/liburing/man/io_uring_prep_statx.3 +74 -0
- data/vendor/liburing/man/io_uring_prep_symlink.3 +1 -0
- data/vendor/liburing/man/io_uring_prep_symlinkat.3 +85 -0
- data/vendor/liburing/man/io_uring_prep_sync_file_range.3 +59 -0
- data/vendor/liburing/man/io_uring_prep_tee.3 +74 -0
- data/vendor/liburing/man/io_uring_prep_timeout.3 +95 -0
- data/vendor/liburing/man/io_uring_prep_timeout_remove.3 +1 -0
- data/vendor/liburing/man/io_uring_prep_timeout_update.3 +98 -0
- data/vendor/liburing/man/io_uring_prep_unlink.3 +1 -0
- data/vendor/liburing/man/io_uring_prep_unlinkat.3 +82 -0
- data/vendor/liburing/man/io_uring_prep_write.3 +32 -15
- data/vendor/liburing/man/io_uring_prep_write_fixed.3 +39 -21
- data/vendor/liburing/man/io_uring_prep_writev.3 +50 -16
- data/vendor/liburing/man/io_uring_prep_writev2.3 +50 -17
- data/vendor/liburing/man/io_uring_queue_exit.3 +3 -4
- data/vendor/liburing/man/io_uring_queue_init.3 +58 -13
- data/vendor/liburing/man/io_uring_queue_init_params.3 +1 -0
- data/vendor/liburing/man/io_uring_recvmsg_cmsg_firsthdr.3 +1 -0
- data/vendor/liburing/man/io_uring_recvmsg_cmsg_nexthdr.3 +1 -0
- data/vendor/liburing/man/io_uring_recvmsg_name.3 +1 -0
- data/vendor/liburing/man/io_uring_recvmsg_out.3 +78 -0
- data/vendor/liburing/man/io_uring_recvmsg_payload.3 +1 -0
- data/vendor/liburing/man/io_uring_recvmsg_payload_length.3 +1 -0
- data/vendor/liburing/man/io_uring_recvmsg_validate.3 +1 -0
- data/vendor/liburing/man/io_uring_register.2 +153 -13
- data/vendor/liburing/man/io_uring_register_buf_ring.3 +140 -0
- data/vendor/liburing/man/io_uring_register_buffers.3 +32 -12
- data/vendor/liburing/man/io_uring_register_eventfd.3 +51 -0
- data/vendor/liburing/man/io_uring_register_eventfd_async.3 +1 -0
- data/vendor/liburing/man/io_uring_register_file_alloc_range.3 +52 -0
- data/vendor/liburing/man/io_uring_register_files.3 +33 -11
- data/vendor/liburing/man/io_uring_register_files_sparse.3 +1 -0
- data/vendor/liburing/man/io_uring_register_iowq_aff.3 +61 -0
- data/vendor/liburing/man/io_uring_register_iowq_max_workers.3 +71 -0
- data/vendor/liburing/man/io_uring_register_ring_fd.3 +49 -0
- data/vendor/liburing/man/io_uring_register_sync_cancel.3 +71 -0
- data/vendor/liburing/man/io_uring_setup.2 +119 -13
- data/vendor/liburing/man/io_uring_sq_ready.3 +14 -8
- data/vendor/liburing/man/io_uring_sq_space_left.3 +9 -9
- data/vendor/liburing/man/io_uring_sqe_set_data.3 +29 -11
- data/vendor/liburing/man/io_uring_sqe_set_data64.3 +1 -0
- data/vendor/liburing/man/io_uring_sqe_set_flags.3 +38 -11
- data/vendor/liburing/man/io_uring_sqring_wait.3 +13 -9
- data/vendor/liburing/man/io_uring_submit.3 +29 -12
- data/vendor/liburing/man/io_uring_submit_and_get_events.3 +31 -0
- data/vendor/liburing/man/io_uring_submit_and_wait.3 +16 -12
- data/vendor/liburing/man/io_uring_submit_and_wait_timeout.3 +30 -23
- data/vendor/liburing/man/io_uring_unregister_buf_ring.3 +30 -0
- data/vendor/liburing/man/io_uring_unregister_buffers.3 +11 -10
- data/vendor/liburing/man/io_uring_unregister_eventfd.3 +1 -0
- data/vendor/liburing/man/io_uring_unregister_files.3 +11 -10
- data/vendor/liburing/man/io_uring_unregister_iowq_aff.3 +1 -0
- data/vendor/liburing/man/io_uring_unregister_ring_fd.3 +32 -0
- data/vendor/liburing/man/io_uring_wait_cqe.3 +19 -12
- data/vendor/liburing/man/io_uring_wait_cqe_nr.3 +21 -14
- data/vendor/liburing/man/io_uring_wait_cqe_timeout.3 +27 -13
- data/vendor/liburing/man/io_uring_wait_cqes.3 +24 -14
- data/vendor/liburing/src/Makefile +8 -7
- data/vendor/liburing/src/arch/aarch64/lib.h +48 -0
- data/vendor/liburing/src/arch/aarch64/syscall.h +0 -4
- data/vendor/liburing/src/arch/generic/lib.h +0 -4
- data/vendor/liburing/src/arch/generic/syscall.h +29 -16
- data/vendor/liburing/src/arch/syscall-defs.h +41 -14
- data/vendor/liburing/src/arch/x86/lib.h +0 -21
- data/vendor/liburing/src/arch/x86/syscall.h +146 -10
- data/vendor/liburing/src/include/liburing/io_uring.h +245 -5
- data/vendor/liburing/src/include/liburing.h +468 -35
- data/vendor/liburing/src/int_flags.h +1 -0
- data/vendor/liburing/src/lib.h +20 -16
- data/vendor/liburing/src/liburing.map +16 -0
- data/vendor/liburing/src/nolibc.c +1 -1
- data/vendor/liburing/src/queue.c +87 -55
- data/vendor/liburing/src/register.c +129 -53
- data/vendor/liburing/src/setup.c +65 -28
- data/vendor/liburing/src/syscall.c +14 -32
- data/vendor/liburing/src/syscall.h +12 -64
- data/vendor/liburing/test/{232c93d07b74-test.c → 232c93d07b74.c} +8 -9
- data/vendor/liburing/test/{35fa71a030ca-test.c → 35fa71a030ca.c} +4 -4
- data/vendor/liburing/test/{500f9fbadef8-test.c → 500f9fbadef8.c} +7 -7
- data/vendor/liburing/test/{7ad0e4b2f83c-test.c → 7ad0e4b2f83c.c} +8 -7
- data/vendor/liburing/test/{8a9973408177-test.c → 8a9973408177.c} +4 -3
- data/vendor/liburing/test/{917257daa0fe-test.c → 917257daa0fe.c} +3 -2
- data/vendor/liburing/test/Makefile +60 -62
- data/vendor/liburing/test/{a0908ae19763-test.c → a0908ae19763.c} +3 -2
- data/vendor/liburing/test/{a4c0b3decb33-test.c → a4c0b3decb33.c} +3 -2
- data/vendor/liburing/test/accept-link.c +5 -4
- data/vendor/liburing/test/accept-reuse.c +17 -16
- data/vendor/liburing/test/accept-test.c +14 -10
- data/vendor/liburing/test/accept.c +529 -107
- data/vendor/liburing/test/across-fork.c +7 -6
- data/vendor/liburing/test/{b19062a56726-test.c → b19062a56726.c} +3 -2
- data/vendor/liburing/test/{b5837bd5311d-test.c → b5837bd5311d.c} +10 -9
- data/vendor/liburing/test/buf-ring.c +420 -0
- data/vendor/liburing/test/{ce593a6c480a-test.c → ce593a6c480a.c} +15 -12
- data/vendor/liburing/test/connect.c +8 -7
- data/vendor/liburing/test/cq-full.c +5 -4
- data/vendor/liburing/test/cq-overflow.c +242 -12
- data/vendor/liburing/test/cq-peek-batch.c +5 -4
- data/vendor/liburing/test/cq-ready.c +5 -4
- data/vendor/liburing/test/cq-size.c +5 -4
- data/vendor/liburing/test/{d4ae271dfaae-test.c → d4ae271dfaae.c} +2 -2
- data/vendor/liburing/test/{d77a67ed5f27-test.c → d77a67ed5f27.c} +6 -6
- data/vendor/liburing/test/defer-taskrun.c +336 -0
- data/vendor/liburing/test/defer.c +26 -14
- data/vendor/liburing/test/double-poll-crash.c +15 -5
- data/vendor/liburing/test/drop-submit.c +5 -3
- data/vendor/liburing/test/{eeed8b54e0df-test.c → eeed8b54e0df.c} +7 -6
- data/vendor/liburing/test/empty-eownerdead.c +4 -4
- data/vendor/liburing/test/eventfd-disable.c +48 -20
- data/vendor/liburing/test/eventfd-reg.c +10 -9
- data/vendor/liburing/test/eventfd-ring.c +13 -12
- data/vendor/liburing/test/eventfd.c +13 -12
- data/vendor/liburing/test/exit-no-cleanup.c +1 -1
- data/vendor/liburing/test/fadvise.c +3 -3
- data/vendor/liburing/test/fallocate.c +16 -9
- data/vendor/liburing/test/{fc2a85cb02ef-test.c → fc2a85cb02ef.c} +4 -3
- data/vendor/liburing/test/fd-pass.c +187 -0
- data/vendor/liburing/test/file-register.c +302 -36
- data/vendor/liburing/test/file-update.c +62 -4
- data/vendor/liburing/test/file-verify.c +6 -2
- data/vendor/liburing/test/files-exit-hang-poll.c +11 -25
- data/vendor/liburing/test/files-exit-hang-timeout.c +13 -10
- data/vendor/liburing/test/fixed-buf-iter.c +115 -0
- data/vendor/liburing/test/fixed-link.c +10 -10
- data/vendor/liburing/test/fixed-reuse.c +160 -0
- data/vendor/liburing/test/fpos.c +6 -3
- data/vendor/liburing/test/fsync.c +3 -3
- data/vendor/liburing/test/hardlink.c +10 -6
- data/vendor/liburing/test/helpers.c +137 -4
- data/vendor/liburing/test/helpers.h +27 -0
- data/vendor/liburing/test/io-cancel.c +16 -11
- data/vendor/liburing/test/io_uring_enter.c +46 -81
- data/vendor/liburing/test/io_uring_passthrough.c +451 -0
- data/vendor/liburing/test/io_uring_register.c +59 -229
- data/vendor/liburing/test/io_uring_setup.c +24 -29
- data/vendor/liburing/test/iopoll-leak.c +85 -0
- data/vendor/liburing/test/iopoll.c +16 -9
- data/vendor/liburing/test/lfs-openat-write.c +3 -1
- data/vendor/liburing/test/link-timeout.c +4 -3
- data/vendor/liburing/test/link.c +8 -7
- data/vendor/liburing/test/madvise.c +2 -2
- data/vendor/liburing/test/mkdir.c +9 -5
- data/vendor/liburing/test/msg-ring.c +46 -20
- data/vendor/liburing/test/multicqes_drain.c +51 -12
- data/vendor/liburing/test/nolibc.c +60 -0
- data/vendor/liburing/test/nop.c +78 -16
- data/vendor/liburing/test/nvme.h +168 -0
- data/vendor/liburing/test/open-direct-link.c +188 -0
- data/vendor/liburing/test/open-direct-pick.c +180 -0
- data/vendor/liburing/test/openat2.c +3 -3
- data/vendor/liburing/test/poll-cancel-all.c +472 -0
- data/vendor/liburing/test/poll-link.c +9 -18
- data/vendor/liburing/test/poll-mshot-overflow.c +162 -0
- data/vendor/liburing/test/poll-mshot-update.c +83 -33
- data/vendor/liburing/test/pollfree.c +2 -2
- data/vendor/liburing/test/read-before-exit.c +112 -0
- data/vendor/liburing/test/read-write.c +83 -1
- data/vendor/liburing/test/recv-msgall-stream.c +398 -0
- data/vendor/liburing/test/recv-msgall.c +265 -0
- data/vendor/liburing/test/recv-multishot.c +505 -0
- data/vendor/liburing/test/rename.c +2 -5
- data/vendor/liburing/test/ring-leak.c +97 -0
- data/vendor/liburing/test/ringbuf-read.c +200 -0
- data/vendor/liburing/test/rsrc_tags.c +25 -13
- data/vendor/liburing/test/runtests-quiet.sh +11 -0
- data/vendor/liburing/test/runtests.sh +18 -20
- data/vendor/liburing/test/rw_merge_test.c +3 -2
- data/vendor/liburing/test/send-zerocopy.c +684 -0
- data/vendor/liburing/test/send_recv.c +49 -2
- data/vendor/liburing/test/send_recvmsg.c +165 -55
- data/vendor/liburing/test/shutdown.c +3 -4
- data/vendor/liburing/test/sigfd-deadlock.c +22 -8
- data/vendor/liburing/test/single-issuer.c +171 -0
- data/vendor/liburing/test/socket-rw-eagain.c +2 -12
- data/vendor/liburing/test/socket-rw-offset.c +2 -11
- data/vendor/liburing/test/socket-rw.c +2 -11
- data/vendor/liburing/test/socket.c +409 -0
- data/vendor/liburing/test/sq-poll-dup.c +1 -1
- data/vendor/liburing/test/sq-poll-share.c +1 -1
- data/vendor/liburing/test/statx.c +2 -2
- data/vendor/liburing/test/submit-and-wait.c +108 -0
- data/vendor/liburing/test/submit-link-fail.c +5 -3
- data/vendor/liburing/test/submit-reuse.c +0 -2
- data/vendor/liburing/test/sync-cancel.c +235 -0
- data/vendor/liburing/test/test.h +35 -0
- data/vendor/liburing/test/timeout-overflow.c +11 -11
- data/vendor/liburing/test/timeout.c +7 -7
- data/vendor/liburing/test/tty-write-dpoll.c +60 -0
- data/vendor/liburing/test/unlink.c +1 -1
- data/vendor/liburing/test/xattr.c +425 -0
- metadata +143 -22
- data/Gemfile.lock +0 -78
@@ -0,0 +1,171 @@
|
|
1
|
+
/* SPDX-License-Identifier: MIT */
|
2
|
+
#include <errno.h>
|
3
|
+
#include <stdio.h>
|
4
|
+
#include <unistd.h>
|
5
|
+
#include <stdlib.h>
|
6
|
+
#include <string.h>
|
7
|
+
#include <fcntl.h>
|
8
|
+
#include <error.h>
|
9
|
+
#include <sys/types.h>
|
10
|
+
#include <sys/wait.h>
|
11
|
+
|
12
|
+
#include "liburing.h"
|
13
|
+
#include "test.h"
|
14
|
+
#include "helpers.h"
|
15
|
+
|
16
|
+
static pid_t pid;
|
17
|
+
|
18
|
+
static pid_t fork_t(void)
|
19
|
+
{
|
20
|
+
pid = fork();
|
21
|
+
if (pid == -1) {
|
22
|
+
fprintf(stderr, "fork failed\n");
|
23
|
+
exit(T_EXIT_FAIL);
|
24
|
+
}
|
25
|
+
return pid;
|
26
|
+
}
|
27
|
+
|
28
|
+
static void wait_child_t(void)
|
29
|
+
{
|
30
|
+
int wstatus;
|
31
|
+
|
32
|
+
if (waitpid(pid, &wstatus, 0) == (pid_t)-1) {
|
33
|
+
perror("waitpid()");
|
34
|
+
exit(T_EXIT_FAIL);
|
35
|
+
}
|
36
|
+
if (!WIFEXITED(wstatus)) {
|
37
|
+
fprintf(stderr, "child failed %i\n", WEXITSTATUS(wstatus));
|
38
|
+
exit(T_EXIT_FAIL);
|
39
|
+
}
|
40
|
+
if (WEXITSTATUS(wstatus))
|
41
|
+
exit(T_EXIT_FAIL);
|
42
|
+
}
|
43
|
+
|
44
|
+
static int try_submit(struct io_uring *ring)
|
45
|
+
{
|
46
|
+
struct io_uring_cqe *cqe;
|
47
|
+
struct io_uring_sqe *sqe;
|
48
|
+
int ret;
|
49
|
+
|
50
|
+
sqe = io_uring_get_sqe(ring);
|
51
|
+
io_uring_prep_nop(sqe);
|
52
|
+
sqe->user_data = 42;
|
53
|
+
|
54
|
+
ret = io_uring_submit(ring);
|
55
|
+
if (ret < 0)
|
56
|
+
return ret;
|
57
|
+
|
58
|
+
if (ret != 1)
|
59
|
+
error(1, ret, "submit %i", ret);
|
60
|
+
ret = io_uring_wait_cqe(ring, &cqe);
|
61
|
+
if (ret)
|
62
|
+
error(1, ret, "wait fail %i", ret);
|
63
|
+
|
64
|
+
if (cqe->res || cqe->user_data != 42)
|
65
|
+
error(1, ret, "invalid cqe");
|
66
|
+
|
67
|
+
io_uring_cqe_seen(ring, cqe);
|
68
|
+
return 0;
|
69
|
+
}
|
70
|
+
|
71
|
+
int main(int argc, char *argv[])
|
72
|
+
{
|
73
|
+
struct io_uring ring;
|
74
|
+
int ret;
|
75
|
+
|
76
|
+
if (argc > 1)
|
77
|
+
return T_EXIT_SKIP;
|
78
|
+
|
79
|
+
ret = io_uring_queue_init(8, &ring, IORING_SETUP_SINGLE_ISSUER);
|
80
|
+
if (ret == -EINVAL) {
|
81
|
+
fprintf(stderr, "SETUP_SINGLE_ISSUER is not supported, skip\n");
|
82
|
+
return T_EXIT_SKIP;
|
83
|
+
} else if (ret) {
|
84
|
+
fprintf(stderr, "io_uring_queue_init() failed %i\n", ret);
|
85
|
+
return T_EXIT_FAIL;
|
86
|
+
}
|
87
|
+
|
88
|
+
/* test that the creator iw allowed to submit */
|
89
|
+
ret = try_submit(&ring);
|
90
|
+
if (ret) {
|
91
|
+
fprintf(stderr, "the creator can't submit %i\n", ret);
|
92
|
+
return T_EXIT_FAIL;
|
93
|
+
}
|
94
|
+
|
95
|
+
/* test that a second submitter doesn't succeed */
|
96
|
+
if (!fork_t()) {
|
97
|
+
ret = try_submit(&ring);
|
98
|
+
if (ret != -EEXIST)
|
99
|
+
fprintf(stderr, "1: not owner child could submit %i\n", ret);
|
100
|
+
return ret != -EEXIST;
|
101
|
+
}
|
102
|
+
wait_child_t();
|
103
|
+
io_uring_queue_exit(&ring);
|
104
|
+
|
105
|
+
/* test that the first submitter but not creator can submit */
|
106
|
+
ret = io_uring_queue_init(8, &ring, IORING_SETUP_SINGLE_ISSUER |
|
107
|
+
IORING_SETUP_R_DISABLED);
|
108
|
+
if (ret)
|
109
|
+
error(1, ret, "ring init (2) %i", ret);
|
110
|
+
|
111
|
+
if (!fork_t()) {
|
112
|
+
io_uring_enable_rings(&ring);
|
113
|
+
ret = try_submit(&ring);
|
114
|
+
if (ret)
|
115
|
+
fprintf(stderr, "2: not owner child could submit %i\n", ret);
|
116
|
+
return !!ret;
|
117
|
+
}
|
118
|
+
wait_child_t();
|
119
|
+
io_uring_queue_exit(&ring);
|
120
|
+
|
121
|
+
/* test that only the first enabler can submit */
|
122
|
+
ret = io_uring_queue_init(8, &ring, IORING_SETUP_SINGLE_ISSUER |
|
123
|
+
IORING_SETUP_R_DISABLED);
|
124
|
+
if (ret)
|
125
|
+
error(1, ret, "ring init (3) %i", ret);
|
126
|
+
|
127
|
+
io_uring_enable_rings(&ring);
|
128
|
+
if (!fork_t()) {
|
129
|
+
ret = try_submit(&ring);
|
130
|
+
if (ret != -EEXIST)
|
131
|
+
fprintf(stderr, "3: not owner child could submit %i\n", ret);
|
132
|
+
return ret != -EEXIST;
|
133
|
+
}
|
134
|
+
wait_child_t();
|
135
|
+
io_uring_queue_exit(&ring);
|
136
|
+
|
137
|
+
/* test that anyone can submit to a SQPOLL|SINGLE_ISSUER ring */
|
138
|
+
ret = io_uring_queue_init(8, &ring, IORING_SETUP_SINGLE_ISSUER|IORING_SETUP_SQPOLL);
|
139
|
+
if (ret)
|
140
|
+
error(1, ret, "ring init (4) %i", ret);
|
141
|
+
|
142
|
+
ret = try_submit(&ring);
|
143
|
+
if (ret) {
|
144
|
+
fprintf(stderr, "SQPOLL submit failed (creator) %i\n", ret);
|
145
|
+
return T_EXIT_FAIL;
|
146
|
+
}
|
147
|
+
|
148
|
+
if (!fork_t()) {
|
149
|
+
ret = try_submit(&ring);
|
150
|
+
if (ret)
|
151
|
+
fprintf(stderr, "SQPOLL submit failed (child) %i\n", ret);
|
152
|
+
return !!ret;
|
153
|
+
}
|
154
|
+
wait_child_t();
|
155
|
+
io_uring_queue_exit(&ring);
|
156
|
+
|
157
|
+
/* test that IORING_ENTER_REGISTERED_RING doesn't break anything */
|
158
|
+
ret = io_uring_queue_init(8, &ring, IORING_SETUP_SINGLE_ISSUER);
|
159
|
+
if (ret)
|
160
|
+
error(1, ret, "ring init (5) %i", ret);
|
161
|
+
|
162
|
+
if (!fork_t()) {
|
163
|
+
ret = try_submit(&ring);
|
164
|
+
if (ret != -EEXIST)
|
165
|
+
fprintf(stderr, "4: not owner child could submit %i\n", ret);
|
166
|
+
return ret != -EEXIST;
|
167
|
+
}
|
168
|
+
wait_child_t();
|
169
|
+
io_uring_queue_exit(&ring);
|
170
|
+
return T_EXIT_PASS;
|
171
|
+
}
|
@@ -18,6 +18,7 @@
|
|
18
18
|
#include <arpa/inet.h>
|
19
19
|
|
20
20
|
#include "liburing.h"
|
21
|
+
#include "helpers.h"
|
21
22
|
|
22
23
|
int main(int argc, char *argv[])
|
23
24
|
{
|
@@ -41,18 +42,7 @@ int main(int argc, char *argv[])
|
|
41
42
|
|
42
43
|
addr.sin_family = AF_INET;
|
43
44
|
addr.sin_addr.s_addr = inet_addr("127.0.0.1");
|
44
|
-
|
45
|
-
do {
|
46
|
-
addr.sin_port = htons((rand() % 61440) + 4096);
|
47
|
-
ret = bind(recv_s0, (struct sockaddr*)&addr, sizeof(addr));
|
48
|
-
if (!ret)
|
49
|
-
break;
|
50
|
-
if (errno != EADDRINUSE) {
|
51
|
-
perror("bind");
|
52
|
-
exit(1);
|
53
|
-
}
|
54
|
-
} while (1);
|
55
|
-
|
45
|
+
assert(!t_bind_ephemeral_port(recv_s0, &addr));
|
56
46
|
ret = listen(recv_s0, 128);
|
57
47
|
assert(ret != -1);
|
58
48
|
|
@@ -20,6 +20,7 @@
|
|
20
20
|
#include <arpa/inet.h>
|
21
21
|
|
22
22
|
#include "liburing.h"
|
23
|
+
#include "helpers.h"
|
23
24
|
|
24
25
|
int main(int argc, char *argv[])
|
25
26
|
{
|
@@ -43,17 +44,7 @@ int main(int argc, char *argv[])
|
|
43
44
|
|
44
45
|
addr.sin_family = AF_INET;
|
45
46
|
addr.sin_addr.s_addr = inet_addr("127.0.0.1");
|
46
|
-
|
47
|
-
do {
|
48
|
-
addr.sin_port = htons((rand() % 61440) + 4096);
|
49
|
-
ret = bind(recv_s0, (struct sockaddr*)&addr, sizeof(addr));
|
50
|
-
if (!ret)
|
51
|
-
break;
|
52
|
-
if (errno != EADDRINUSE) {
|
53
|
-
perror("bind");
|
54
|
-
exit(1);
|
55
|
-
}
|
56
|
-
} while (1);
|
47
|
+
assert(!t_bind_ephemeral_port(recv_s0, &addr));
|
57
48
|
ret = listen(recv_s0, 128);
|
58
49
|
assert(ret != -1);
|
59
50
|
|
@@ -20,6 +20,7 @@
|
|
20
20
|
#include <arpa/inet.h>
|
21
21
|
|
22
22
|
#include "liburing.h"
|
23
|
+
#include "helpers.h"
|
23
24
|
|
24
25
|
int main(int argc, char *argv[])
|
25
26
|
{
|
@@ -43,17 +44,7 @@ int main(int argc, char *argv[])
|
|
43
44
|
|
44
45
|
addr.sin_family = AF_INET;
|
45
46
|
addr.sin_addr.s_addr = inet_addr("127.0.0.1");
|
46
|
-
|
47
|
-
do {
|
48
|
-
addr.sin_port = htons((rand() % 61440) + 4096);
|
49
|
-
ret = bind(recv_s0, (struct sockaddr*)&addr, sizeof(addr));
|
50
|
-
if (!ret)
|
51
|
-
break;
|
52
|
-
if (errno != EADDRINUSE) {
|
53
|
-
perror("bind");
|
54
|
-
exit(1);
|
55
|
-
}
|
56
|
-
} while (1);
|
47
|
+
assert(!t_bind_ephemeral_port(recv_s0, &addr));
|
57
48
|
ret = listen(recv_s0, 128);
|
58
49
|
assert(ret != -1);
|
59
50
|
|
@@ -0,0 +1,409 @@
|
|
1
|
+
/* SPDX-License-Identifier: MIT */
|
2
|
+
/*
|
3
|
+
* Simple test case using the socket op
|
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
|
+
#include <assert.h>
|
15
|
+
|
16
|
+
#include "liburing.h"
|
17
|
+
#include "helpers.h"
|
18
|
+
|
19
|
+
static char str[] = "This is a test of send and recv over io_uring!";
|
20
|
+
|
21
|
+
#define MAX_MSG 128
|
22
|
+
|
23
|
+
#define HOST "127.0.0.1"
|
24
|
+
|
25
|
+
static int no_socket;
|
26
|
+
static __be32 g_port;
|
27
|
+
|
28
|
+
static int recv_prep(struct io_uring *ring, struct iovec *iov, int *sock,
|
29
|
+
int registerfiles)
|
30
|
+
{
|
31
|
+
struct sockaddr_in saddr;
|
32
|
+
struct io_uring_sqe *sqe;
|
33
|
+
int sockfd, ret, val, use_fd;
|
34
|
+
|
35
|
+
memset(&saddr, 0, sizeof(saddr));
|
36
|
+
saddr.sin_family = AF_INET;
|
37
|
+
saddr.sin_addr.s_addr = htonl(INADDR_ANY);
|
38
|
+
|
39
|
+
sockfd = socket(AF_INET, SOCK_DGRAM, 0);
|
40
|
+
if (sockfd < 0) {
|
41
|
+
perror("socket");
|
42
|
+
return 1;
|
43
|
+
}
|
44
|
+
|
45
|
+
val = 1;
|
46
|
+
setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, &val, sizeof(val));
|
47
|
+
|
48
|
+
if (t_bind_ephemeral_port(sockfd, &saddr)) {
|
49
|
+
perror("bind");
|
50
|
+
goto err;
|
51
|
+
}
|
52
|
+
g_port = saddr.sin_port;
|
53
|
+
|
54
|
+
if (registerfiles) {
|
55
|
+
ret = io_uring_register_files(ring, &sockfd, 1);
|
56
|
+
if (ret) {
|
57
|
+
fprintf(stderr, "file reg failed\n");
|
58
|
+
goto err;
|
59
|
+
}
|
60
|
+
use_fd = 0;
|
61
|
+
} else {
|
62
|
+
use_fd = sockfd;
|
63
|
+
}
|
64
|
+
|
65
|
+
sqe = io_uring_get_sqe(ring);
|
66
|
+
io_uring_prep_recv(sqe, use_fd, iov->iov_base, iov->iov_len, 0);
|
67
|
+
if (registerfiles)
|
68
|
+
sqe->flags |= IOSQE_FIXED_FILE;
|
69
|
+
sqe->user_data = 2;
|
70
|
+
|
71
|
+
ret = io_uring_submit(ring);
|
72
|
+
if (ret <= 0) {
|
73
|
+
fprintf(stderr, "submit failed: %d\n", ret);
|
74
|
+
goto err;
|
75
|
+
}
|
76
|
+
|
77
|
+
*sock = sockfd;
|
78
|
+
return 0;
|
79
|
+
err:
|
80
|
+
close(sockfd);
|
81
|
+
return 1;
|
82
|
+
}
|
83
|
+
|
84
|
+
static int do_recv(struct io_uring *ring, struct iovec *iov)
|
85
|
+
{
|
86
|
+
struct io_uring_cqe *cqe;
|
87
|
+
int ret;
|
88
|
+
|
89
|
+
ret = io_uring_wait_cqe(ring, &cqe);
|
90
|
+
if (ret) {
|
91
|
+
fprintf(stdout, "wait_cqe: %d\n", ret);
|
92
|
+
goto err;
|
93
|
+
}
|
94
|
+
if (cqe->res == -EINVAL) {
|
95
|
+
fprintf(stdout, "recv not supported, skipping\n");
|
96
|
+
return 0;
|
97
|
+
}
|
98
|
+
if (cqe->res < 0) {
|
99
|
+
fprintf(stderr, "failed cqe: %d\n", cqe->res);
|
100
|
+
goto err;
|
101
|
+
}
|
102
|
+
|
103
|
+
if (cqe->res -1 != strlen(str)) {
|
104
|
+
fprintf(stderr, "got wrong length: %d/%d\n", cqe->res,
|
105
|
+
(int) strlen(str) + 1);
|
106
|
+
goto err;
|
107
|
+
}
|
108
|
+
|
109
|
+
if (strcmp(str, iov->iov_base)) {
|
110
|
+
fprintf(stderr, "string mismatch\n");
|
111
|
+
goto err;
|
112
|
+
}
|
113
|
+
|
114
|
+
return 0;
|
115
|
+
err:
|
116
|
+
return 1;
|
117
|
+
}
|
118
|
+
|
119
|
+
struct recv_data {
|
120
|
+
pthread_mutex_t mutex;
|
121
|
+
int use_sqthread;
|
122
|
+
int registerfiles;
|
123
|
+
};
|
124
|
+
|
125
|
+
static void *recv_fn(void *data)
|
126
|
+
{
|
127
|
+
struct recv_data *rd = data;
|
128
|
+
char buf[MAX_MSG + 1];
|
129
|
+
struct iovec iov = {
|
130
|
+
.iov_base = buf,
|
131
|
+
.iov_len = sizeof(buf) - 1,
|
132
|
+
};
|
133
|
+
struct io_uring_params p = { };
|
134
|
+
struct io_uring ring;
|
135
|
+
int ret, sock;
|
136
|
+
|
137
|
+
if (rd->use_sqthread)
|
138
|
+
p.flags = IORING_SETUP_SQPOLL;
|
139
|
+
ret = t_create_ring_params(1, &ring, &p);
|
140
|
+
if (ret == T_SETUP_SKIP) {
|
141
|
+
pthread_mutex_unlock(&rd->mutex);
|
142
|
+
ret = 0;
|
143
|
+
goto err;
|
144
|
+
} else if (ret < 0) {
|
145
|
+
pthread_mutex_unlock(&rd->mutex);
|
146
|
+
goto err;
|
147
|
+
}
|
148
|
+
|
149
|
+
if (rd->use_sqthread && !rd->registerfiles) {
|
150
|
+
if (!(p.features & IORING_FEAT_SQPOLL_NONFIXED)) {
|
151
|
+
fprintf(stdout, "Non-registered SQPOLL not available, skipping\n");
|
152
|
+
pthread_mutex_unlock(&rd->mutex);
|
153
|
+
goto err;
|
154
|
+
}
|
155
|
+
}
|
156
|
+
|
157
|
+
ret = recv_prep(&ring, &iov, &sock, rd->registerfiles);
|
158
|
+
if (ret) {
|
159
|
+
fprintf(stderr, "recv_prep failed: %d\n", ret);
|
160
|
+
goto err;
|
161
|
+
}
|
162
|
+
pthread_mutex_unlock(&rd->mutex);
|
163
|
+
ret = do_recv(&ring, &iov);
|
164
|
+
|
165
|
+
close(sock);
|
166
|
+
io_uring_queue_exit(&ring);
|
167
|
+
err:
|
168
|
+
return (void *)(intptr_t)ret;
|
169
|
+
}
|
170
|
+
|
171
|
+
static int fallback_send(struct io_uring *ring, struct sockaddr_in *saddr)
|
172
|
+
{
|
173
|
+
struct iovec iov = {
|
174
|
+
.iov_base = str,
|
175
|
+
.iov_len = sizeof(str),
|
176
|
+
};
|
177
|
+
struct io_uring_cqe *cqe;
|
178
|
+
struct io_uring_sqe *sqe;
|
179
|
+
int sockfd, ret;
|
180
|
+
|
181
|
+
sockfd = socket(AF_INET, SOCK_DGRAM, 0);
|
182
|
+
if (sockfd < 0) {
|
183
|
+
perror("socket");
|
184
|
+
return 1;
|
185
|
+
}
|
186
|
+
|
187
|
+
ret = connect(sockfd, (struct sockaddr *)saddr, sizeof(*saddr));
|
188
|
+
if (ret < 0) {
|
189
|
+
perror("connect");
|
190
|
+
return 1;
|
191
|
+
}
|
192
|
+
|
193
|
+
sqe = io_uring_get_sqe(ring);
|
194
|
+
io_uring_prep_send(sqe, sockfd, iov.iov_base, iov.iov_len, 0);
|
195
|
+
sqe->user_data = 1;
|
196
|
+
|
197
|
+
ret = io_uring_submit(ring);
|
198
|
+
if (ret <= 0) {
|
199
|
+
fprintf(stderr, "submit failed: %d\n", ret);
|
200
|
+
goto err;
|
201
|
+
}
|
202
|
+
|
203
|
+
ret = io_uring_wait_cqe(ring, &cqe);
|
204
|
+
if (cqe->res == -EINVAL) {
|
205
|
+
fprintf(stdout, "send not supported, skipping\n");
|
206
|
+
close(sockfd);
|
207
|
+
return 0;
|
208
|
+
}
|
209
|
+
if (cqe->res != iov.iov_len) {
|
210
|
+
fprintf(stderr, "failed cqe: %d\n", cqe->res);
|
211
|
+
goto err;
|
212
|
+
}
|
213
|
+
|
214
|
+
close(sockfd);
|
215
|
+
return 0;
|
216
|
+
err:
|
217
|
+
close(sockfd);
|
218
|
+
return 1;
|
219
|
+
}
|
220
|
+
|
221
|
+
static int do_send(int socket_direct, int alloc)
|
222
|
+
{
|
223
|
+
struct sockaddr_in saddr;
|
224
|
+
struct iovec iov = {
|
225
|
+
.iov_base = str,
|
226
|
+
.iov_len = sizeof(str),
|
227
|
+
};
|
228
|
+
struct io_uring ring;
|
229
|
+
struct io_uring_cqe *cqe;
|
230
|
+
struct io_uring_sqe *sqe;
|
231
|
+
int sockfd, ret, fd = -1;
|
232
|
+
|
233
|
+
ret = io_uring_queue_init(1, &ring, 0);
|
234
|
+
if (ret) {
|
235
|
+
fprintf(stderr, "queue init failed: %d\n", ret);
|
236
|
+
return 1;
|
237
|
+
}
|
238
|
+
|
239
|
+
if (socket_direct) {
|
240
|
+
ret = io_uring_register_files(&ring, &fd, 1);
|
241
|
+
if (ret) {
|
242
|
+
fprintf(stderr, "file register %d\n", ret);
|
243
|
+
return 1;
|
244
|
+
}
|
245
|
+
}
|
246
|
+
|
247
|
+
assert(g_port != 0);
|
248
|
+
memset(&saddr, 0, sizeof(saddr));
|
249
|
+
saddr.sin_family = AF_INET;
|
250
|
+
saddr.sin_port = g_port;
|
251
|
+
inet_pton(AF_INET, HOST, &saddr.sin_addr);
|
252
|
+
|
253
|
+
sqe = io_uring_get_sqe(&ring);
|
254
|
+
if (socket_direct) {
|
255
|
+
unsigned file_index = 0;
|
256
|
+
if (alloc)
|
257
|
+
file_index = IORING_FILE_INDEX_ALLOC - 1;
|
258
|
+
io_uring_prep_socket_direct(sqe, AF_INET, SOCK_DGRAM, 0,
|
259
|
+
file_index, 0);
|
260
|
+
} else {
|
261
|
+
io_uring_prep_socket(sqe, AF_INET, SOCK_DGRAM, 0, 0);
|
262
|
+
}
|
263
|
+
ret = io_uring_submit(&ring);
|
264
|
+
if (ret != 1) {
|
265
|
+
fprintf(stderr, "socket submit: %d\n", ret);
|
266
|
+
return 1;
|
267
|
+
}
|
268
|
+
ret = io_uring_wait_cqe(&ring, &cqe);
|
269
|
+
if (ret) {
|
270
|
+
fprintf(stderr, "wait_cqe: %d\n", ret);
|
271
|
+
return 1;
|
272
|
+
}
|
273
|
+
if (cqe->res < 0) {
|
274
|
+
if (cqe->res == -EINVAL) {
|
275
|
+
fprintf(stdout, "No socket support, skipping\n");
|
276
|
+
no_socket = 1;
|
277
|
+
io_uring_cqe_seen(&ring, cqe);
|
278
|
+
return fallback_send(&ring, &saddr);
|
279
|
+
}
|
280
|
+
|
281
|
+
fprintf(stderr, "socket res: %d\n", ret);
|
282
|
+
return 1;
|
283
|
+
}
|
284
|
+
|
285
|
+
sockfd = cqe->res;
|
286
|
+
if (socket_direct && !alloc)
|
287
|
+
sockfd = 0;
|
288
|
+
io_uring_cqe_seen(&ring, cqe);
|
289
|
+
|
290
|
+
sqe = io_uring_get_sqe(&ring);
|
291
|
+
io_uring_prep_connect(sqe, sockfd, (struct sockaddr *) &saddr,
|
292
|
+
sizeof(saddr));
|
293
|
+
if (socket_direct)
|
294
|
+
sqe->flags |= IOSQE_FIXED_FILE;
|
295
|
+
ret = io_uring_submit(&ring);
|
296
|
+
if (ret != 1) {
|
297
|
+
fprintf(stderr, "connect submit: %d\n", ret);
|
298
|
+
return 1;
|
299
|
+
}
|
300
|
+
ret = io_uring_wait_cqe(&ring, &cqe);
|
301
|
+
if (ret) {
|
302
|
+
fprintf(stderr, "wait_cqe: %d\n", ret);
|
303
|
+
return 1;
|
304
|
+
}
|
305
|
+
if (cqe->res < 0) {
|
306
|
+
fprintf(stderr, "connect res: %d\n", cqe->res);
|
307
|
+
return 1;
|
308
|
+
}
|
309
|
+
io_uring_cqe_seen(&ring, cqe);
|
310
|
+
|
311
|
+
sqe = io_uring_get_sqe(&ring);
|
312
|
+
io_uring_prep_send(sqe, sockfd, iov.iov_base, iov.iov_len, 0);
|
313
|
+
sqe->user_data = 1;
|
314
|
+
if (socket_direct)
|
315
|
+
sqe->flags |= IOSQE_FIXED_FILE;
|
316
|
+
|
317
|
+
ret = io_uring_submit(&ring);
|
318
|
+
if (ret <= 0) {
|
319
|
+
fprintf(stderr, "submit failed: %d\n", ret);
|
320
|
+
goto err;
|
321
|
+
}
|
322
|
+
|
323
|
+
ret = io_uring_wait_cqe(&ring, &cqe);
|
324
|
+
if (cqe->res == -EINVAL) {
|
325
|
+
fprintf(stdout, "send not supported, skipping\n");
|
326
|
+
close(sockfd);
|
327
|
+
return 0;
|
328
|
+
}
|
329
|
+
if (cqe->res != iov.iov_len) {
|
330
|
+
fprintf(stderr, "failed cqe: %d\n", cqe->res);
|
331
|
+
goto err;
|
332
|
+
}
|
333
|
+
|
334
|
+
close(sockfd);
|
335
|
+
return 0;
|
336
|
+
err:
|
337
|
+
close(sockfd);
|
338
|
+
return 1;
|
339
|
+
}
|
340
|
+
|
341
|
+
static int test(int use_sqthread, int regfiles, int socket_direct, int alloc)
|
342
|
+
{
|
343
|
+
pthread_mutexattr_t attr;
|
344
|
+
pthread_t recv_thread;
|
345
|
+
struct recv_data rd;
|
346
|
+
int ret;
|
347
|
+
void *retval;
|
348
|
+
|
349
|
+
pthread_mutexattr_init(&attr);
|
350
|
+
pthread_mutexattr_setpshared(&attr, 1);
|
351
|
+
pthread_mutex_init(&rd.mutex, &attr);
|
352
|
+
pthread_mutex_lock(&rd.mutex);
|
353
|
+
rd.use_sqthread = use_sqthread;
|
354
|
+
rd.registerfiles = regfiles;
|
355
|
+
|
356
|
+
ret = pthread_create(&recv_thread, NULL, recv_fn, &rd);
|
357
|
+
if (ret) {
|
358
|
+
fprintf(stderr, "Thread create failed: %d\n", ret);
|
359
|
+
pthread_mutex_unlock(&rd.mutex);
|
360
|
+
return 1;
|
361
|
+
}
|
362
|
+
|
363
|
+
pthread_mutex_lock(&rd.mutex);
|
364
|
+
do_send(socket_direct, alloc);
|
365
|
+
pthread_join(recv_thread, &retval);
|
366
|
+
return (intptr_t)retval;
|
367
|
+
}
|
368
|
+
|
369
|
+
int main(int argc, char *argv[])
|
370
|
+
{
|
371
|
+
int ret;
|
372
|
+
|
373
|
+
if (argc > 1)
|
374
|
+
return 0;
|
375
|
+
|
376
|
+
ret = test(0, 0, 0, 0);
|
377
|
+
if (ret) {
|
378
|
+
fprintf(stderr, "test sqthread=0 failed\n");
|
379
|
+
return ret;
|
380
|
+
}
|
381
|
+
if (no_socket)
|
382
|
+
return 0;
|
383
|
+
|
384
|
+
ret = test(1, 1, 0, 0);
|
385
|
+
if (ret) {
|
386
|
+
fprintf(stderr, "test sqthread=1 reg=1 failed\n");
|
387
|
+
return ret;
|
388
|
+
}
|
389
|
+
|
390
|
+
ret = test(1, 0, 0, 0);
|
391
|
+
if (ret) {
|
392
|
+
fprintf(stderr, "test sqthread=1 reg=0 failed\n");
|
393
|
+
return ret;
|
394
|
+
}
|
395
|
+
|
396
|
+
ret = test(0, 0, 1, 0);
|
397
|
+
if (ret) {
|
398
|
+
fprintf(stderr, "test sqthread=0 direct=1 failed\n");
|
399
|
+
return ret;
|
400
|
+
}
|
401
|
+
|
402
|
+
ret = test(0, 0, 1, 1);
|
403
|
+
if (ret) {
|
404
|
+
fprintf(stderr, "test sqthread=0 direct=alloc failed\n");
|
405
|
+
return ret;
|
406
|
+
}
|
407
|
+
|
408
|
+
return 0;
|
409
|
+
}
|
@@ -11,7 +11,7 @@
|
|
11
11
|
#include <fcntl.h>
|
12
12
|
#include <sys/types.h>
|
13
13
|
#include <sys/syscall.h>
|
14
|
-
#include <
|
14
|
+
#include <sys/stat.h>
|
15
15
|
|
16
16
|
#include "helpers.h"
|
17
17
|
#include "liburing.h"
|
@@ -40,7 +40,7 @@ static int test_statx(struct io_uring *ring, const char *path)
|
|
40
40
|
{
|
41
41
|
struct io_uring_cqe *cqe;
|
42
42
|
struct io_uring_sqe *sqe;
|
43
|
-
struct statx x1, x2;
|
43
|
+
struct statx x1 = { }, x2 = { };
|
44
44
|
int ret;
|
45
45
|
|
46
46
|
sqe = io_uring_get_sqe(ring);
|