uringmachine 0.15 → 0.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (261) hide show
  1. checksums.yaml +4 -4
  2. data/.github/FUNDING.yml +3 -0
  3. data/.gitmodules +4 -0
  4. data/CHANGELOG.md +12 -0
  5. data/TODO.md +12 -3
  6. data/examples/bm_send.rb +86 -0
  7. data/ext/um/um.c +28 -1
  8. data/ext/um/um.h +3 -0
  9. data/ext/um/um_class.c +17 -0
  10. data/ext/um/um_stream_class.c +0 -1
  11. data/ext/um/um_utils.c +38 -15
  12. data/lib/uringmachine/version.rb +1 -1
  13. data/lib/uringmachine.rb +4 -3
  14. data/test/test_um.rb +76 -0
  15. data/vendor/libressl/.github/scripts/changelog.sh +74 -0
  16. data/vendor/libressl/.github/workflows/android.yml +35 -0
  17. data/vendor/libressl/.github/workflows/cifuzz.yml +33 -0
  18. data/vendor/libressl/.github/workflows/cmake-config.yml +98 -0
  19. data/vendor/libressl/.github/workflows/coverity.yml +69 -0
  20. data/vendor/libressl/.github/workflows/emscripten.yml +71 -0
  21. data/vendor/libressl/.github/workflows/fedora-rawhide.yml +39 -0
  22. data/vendor/libressl/.github/workflows/freebsd.yml +71 -0
  23. data/vendor/libressl/.github/workflows/linux.yml +71 -0
  24. data/vendor/libressl/.github/workflows/macos.yml +37 -0
  25. data/vendor/libressl/.github/workflows/release.yml +81 -0
  26. data/vendor/libressl/.github/workflows/rust-openssl.yml +47 -0
  27. data/vendor/libressl/.github/workflows/solaris.yml +37 -0
  28. data/vendor/libressl/.github/workflows/windows.yml +70 -0
  29. data/vendor/libressl/.gitignore +333 -0
  30. data/vendor/libressl/CMakeLists.txt +581 -0
  31. data/vendor/libressl/COPYING +133 -0
  32. data/vendor/libressl/ChangeLog +3280 -0
  33. data/vendor/libressl/FindLibreSSL.cmake +232 -0
  34. data/vendor/libressl/LibreSSLConfig.cmake.in +36 -0
  35. data/vendor/libressl/Makefile.am +60 -0
  36. data/vendor/libressl/Makefile.am.common +20 -0
  37. data/vendor/libressl/OPENBSD_BRANCH +1 -0
  38. data/vendor/libressl/README.md +238 -0
  39. data/vendor/libressl/README.mingw.md +43 -0
  40. data/vendor/libressl/apps/CMakeLists.txt +18 -0
  41. data/vendor/libressl/apps/Makefile.am +5 -0
  42. data/vendor/libressl/apps/nc/CMakeLists.txt +67 -0
  43. data/vendor/libressl/apps/nc/Makefile.am +64 -0
  44. data/vendor/libressl/apps/nc/compat/accept4.c +17 -0
  45. data/vendor/libressl/apps/nc/compat/readpassphrase.c +205 -0
  46. data/vendor/libressl/apps/nc/compat/socket.c +29 -0
  47. data/vendor/libressl/apps/nc/compat/sys/socket.h +30 -0
  48. data/vendor/libressl/apps/ocspcheck/CMakeLists.txt +44 -0
  49. data/vendor/libressl/apps/ocspcheck/Makefile.am +45 -0
  50. data/vendor/libressl/apps/ocspcheck/compat/.gitignore +0 -0
  51. data/vendor/libressl/apps/openssl/CMakeLists.txt +97 -0
  52. data/vendor/libressl/apps/openssl/Makefile.am +108 -0
  53. data/vendor/libressl/apps/openssl/apps_win.c +138 -0
  54. data/vendor/libressl/apps/openssl/certhash_win.c +13 -0
  55. data/vendor/libressl/apps/openssl/compat/clock_gettime_osx.c +26 -0
  56. data/vendor/libressl/apps/openssl/compat/poll_win.c +329 -0
  57. data/vendor/libressl/appveyor.yml +53 -0
  58. data/vendor/libressl/autogen.sh +15 -0
  59. data/vendor/libressl/check-release.sh +86 -0
  60. data/vendor/libressl/cmake_export_symbol.cmake +71 -0
  61. data/vendor/libressl/cmake_uninstall.cmake.in +36 -0
  62. data/vendor/libressl/config +17 -0
  63. data/vendor/libressl/configure.ac +165 -0
  64. data/vendor/libressl/crypto/CMakeLists.txt +863 -0
  65. data/vendor/libressl/crypto/Makefile.am +962 -0
  66. data/vendor/libressl/crypto/Makefile.am.arc4random +46 -0
  67. data/vendor/libressl/crypto/Makefile.am.elf-mips +14 -0
  68. data/vendor/libressl/crypto/Makefile.am.elf-mips64 +14 -0
  69. data/vendor/libressl/crypto/Makefile.am.elf-x86_64 +35 -0
  70. data/vendor/libressl/crypto/Makefile.am.macosx-x86_64 +35 -0
  71. data/vendor/libressl/crypto/Makefile.am.masm-x86_64 +22 -0
  72. data/vendor/libressl/crypto/Makefile.am.mingw64-x86_64 +23 -0
  73. data/vendor/libressl/crypto/arch/aarch64/crypto_cpu_caps_darwin.c +60 -0
  74. data/vendor/libressl/crypto/arch/aarch64/crypto_cpu_caps_linux.c +62 -0
  75. data/vendor/libressl/crypto/arch/aarch64/crypto_cpu_caps_none.c +26 -0
  76. data/vendor/libressl/crypto/arch/aarch64/crypto_cpu_caps_windows.c +36 -0
  77. data/vendor/libressl/crypto/arch/loongarch64/crypto_arch.h +21 -0
  78. data/vendor/libressl/crypto/arch/mips/crypto_arch.h +21 -0
  79. data/vendor/libressl/crypto/bn/arch/loongarch64/bn_arch.h +23 -0
  80. data/vendor/libressl/crypto/bn/arch/mips/bn_arch.h +24 -0
  81. data/vendor/libressl/crypto/compat/.gitignore +31 -0
  82. data/vendor/libressl/crypto/compat/arc4random.h +41 -0
  83. data/vendor/libressl/crypto/compat/b_win.c +55 -0
  84. data/vendor/libressl/crypto/compat/bsd-asprintf.c +96 -0
  85. data/vendor/libressl/crypto/compat/crypto_lock_win.c +56 -0
  86. data/vendor/libressl/crypto/compat/explicit_bzero_win.c +13 -0
  87. data/vendor/libressl/crypto/compat/freezero.c +32 -0
  88. data/vendor/libressl/crypto/compat/getdelim.c +78 -0
  89. data/vendor/libressl/crypto/compat/getline.c +40 -0
  90. data/vendor/libressl/crypto/compat/getopt_long.c +528 -0
  91. data/vendor/libressl/crypto/compat/getpagesize.c +18 -0
  92. data/vendor/libressl/crypto/compat/getprogname_linux.c +23 -0
  93. data/vendor/libressl/crypto/compat/getprogname_unimpl.c +7 -0
  94. data/vendor/libressl/crypto/compat/getprogname_windows.c +13 -0
  95. data/vendor/libressl/crypto/compat/posix_win.c +296 -0
  96. data/vendor/libressl/crypto/compat/syslog_r.c +19 -0
  97. data/vendor/libressl/crypto/compat/ui_openssl_win.c +334 -0
  98. data/vendor/libressl/dist.sh +22 -0
  99. data/vendor/libressl/gen-coverage-report.sh +58 -0
  100. data/vendor/libressl/gen-openbsd-tags.sh +20 -0
  101. data/vendor/libressl/include/CMakeLists.txt +61 -0
  102. data/vendor/libressl/include/Makefile.am +79 -0
  103. data/vendor/libressl/include/arch/loongarch64/opensslconf.h +150 -0
  104. data/vendor/libressl/include/arch/mips/opensslconf.h +150 -0
  105. data/vendor/libressl/include/compat/arpa/inet.h +15 -0
  106. data/vendor/libressl/include/compat/arpa/nameser.h +25 -0
  107. data/vendor/libressl/include/compat/cet.h +19 -0
  108. data/vendor/libressl/include/compat/dirent.h +17 -0
  109. data/vendor/libressl/include/compat/dirent_msvc.h +611 -0
  110. data/vendor/libressl/include/compat/endian.h +161 -0
  111. data/vendor/libressl/include/compat/err.h +95 -0
  112. data/vendor/libressl/include/compat/fcntl.h +32 -0
  113. data/vendor/libressl/include/compat/getopt.h +50 -0
  114. data/vendor/libressl/include/compat/limits.h +25 -0
  115. data/vendor/libressl/include/compat/netdb.h +10 -0
  116. data/vendor/libressl/include/compat/netinet/in.h +19 -0
  117. data/vendor/libressl/include/compat/netinet/ip.h +49 -0
  118. data/vendor/libressl/include/compat/netinet/tcp.h +10 -0
  119. data/vendor/libressl/include/compat/poll.h +63 -0
  120. data/vendor/libressl/include/compat/pthread.h +122 -0
  121. data/vendor/libressl/include/compat/readpassphrase.h +44 -0
  122. data/vendor/libressl/include/compat/resolv.h +24 -0
  123. data/vendor/libressl/include/compat/stdint.h +31 -0
  124. data/vendor/libressl/include/compat/stdio.h +65 -0
  125. data/vendor/libressl/include/compat/stdlib.h +57 -0
  126. data/vendor/libressl/include/compat/string.h +98 -0
  127. data/vendor/libressl/include/compat/sys/_null.h +18 -0
  128. data/vendor/libressl/include/compat/sys/ioctl.h +11 -0
  129. data/vendor/libressl/include/compat/sys/mman.h +19 -0
  130. data/vendor/libressl/include/compat/sys/param.h +15 -0
  131. data/vendor/libressl/include/compat/sys/queue.h +536 -0
  132. data/vendor/libressl/include/compat/sys/select.h +10 -0
  133. data/vendor/libressl/include/compat/sys/socket.h +18 -0
  134. data/vendor/libressl/include/compat/sys/stat.h +129 -0
  135. data/vendor/libressl/include/compat/sys/time.h +37 -0
  136. data/vendor/libressl/include/compat/sys/tree.h +1006 -0
  137. data/vendor/libressl/include/compat/sys/types.h +69 -0
  138. data/vendor/libressl/include/compat/sys/uio.h +17 -0
  139. data/vendor/libressl/include/compat/syslog.h +38 -0
  140. data/vendor/libressl/include/compat/time.h +59 -0
  141. data/vendor/libressl/include/compat/unistd.h +83 -0
  142. data/vendor/libressl/include/compat/win32netcompat.h +57 -0
  143. data/vendor/libressl/include/openssl/Makefile.am.tpl +45 -0
  144. data/vendor/libressl/libcrypto.pc.in +28 -0
  145. data/vendor/libressl/libressl.pub +2 -0
  146. data/vendor/libressl/libssl.pc.in +28 -0
  147. data/vendor/libressl/libtls.pc.in +28 -0
  148. data/vendor/libressl/m4/ax_add_fortify_source.m4 +80 -0
  149. data/vendor/libressl/m4/ax_check_compile_flag.m4 +53 -0
  150. data/vendor/libressl/m4/check-hardening-options.m4 +110 -0
  151. data/vendor/libressl/m4/check-libc.m4 +189 -0
  152. data/vendor/libressl/m4/check-os-options.m4 +181 -0
  153. data/vendor/libressl/m4/disable-compiler-warnings.m4 +44 -0
  154. data/vendor/libressl/man/CMakeLists.txt +26 -0
  155. data/vendor/libressl/man/links +2780 -0
  156. data/vendor/libressl/man/update_links.sh +25 -0
  157. data/vendor/libressl/openssl.pc.in +11 -0
  158. data/vendor/libressl/patches/bn_shift.patch +34 -0
  159. data/vendor/libressl/patches/crypto_arch.h.patch +34 -0
  160. data/vendor/libressl/patches/crypto_namespace.h.patch +22 -0
  161. data/vendor/libressl/patches/netcat.c.patch +178 -0
  162. data/vendor/libressl/patches/openssl.c.patch +12 -0
  163. data/vendor/libressl/patches/opensslfeatures.h.patch +49 -0
  164. data/vendor/libressl/patches/patch-amd64-crypto-cpu-caps.c.patch +20 -0
  165. data/vendor/libressl/patches/patch-i386-crypto-cpu-caps.c.patch +20 -0
  166. data/vendor/libressl/patches/speed.c.patch +114 -0
  167. data/vendor/libressl/patches/ssl_namespace.h.patch +21 -0
  168. data/vendor/libressl/patches/tls.h.patch +16 -0
  169. data/vendor/libressl/patches/tls_config.c.patch +15 -0
  170. data/vendor/libressl/patches/win32_amd64_bn_arch.h.patch +28 -0
  171. data/vendor/libressl/patches/windows_headers.patch +80 -0
  172. data/vendor/libressl/scripts/config.guess +1774 -0
  173. data/vendor/libressl/scripts/config.sub +1907 -0
  174. data/vendor/libressl/scripts/i686-w64-mingw32.cmake +9 -0
  175. data/vendor/libressl/scripts/test +210 -0
  176. data/vendor/libressl/scripts/wrap-compiler-for-flag-check +31 -0
  177. data/vendor/libressl/scripts/x86_64-w64-mingw32.cmake +9 -0
  178. data/vendor/libressl/ssl/CMakeLists.txt +183 -0
  179. data/vendor/libressl/ssl/Makefile.am +187 -0
  180. data/vendor/libressl/tests/CMakeLists.txt +970 -0
  181. data/vendor/libressl/tests/Makefile.am +944 -0
  182. data/vendor/libressl/tests/aeadtest.sh +30 -0
  183. data/vendor/libressl/tests/arc4randomforktest.sh +21 -0
  184. data/vendor/libressl/tests/asn1time_small.test +10 -0
  185. data/vendor/libressl/tests/cmake/CMakeLists.txt +52 -0
  186. data/vendor/libressl/tests/cmake/crypto.c +7 -0
  187. data/vendor/libressl/tests/cmake/ssl.c +6 -0
  188. data/vendor/libressl/tests/cmake/tls.c +6 -0
  189. data/vendor/libressl/tests/compat/pipe2.c +186 -0
  190. data/vendor/libressl/tests/dtlstest.sh +28 -0
  191. data/vendor/libressl/tests/evptest.sh +22 -0
  192. data/vendor/libressl/tests/keypairtest.sh +27 -0
  193. data/vendor/libressl/tests/mlkem_tests.sh +39 -0
  194. data/vendor/libressl/tests/ocsptest.bat +25 -0
  195. data/vendor/libressl/tests/ocsptest.sh +23 -0
  196. data/vendor/libressl/tests/openssl.cnf +29 -0
  197. data/vendor/libressl/tests/optionstest.c +381 -0
  198. data/vendor/libressl/tests/pidwraptest.c +85 -0
  199. data/vendor/libressl/tests/pidwraptest.sh +26 -0
  200. data/vendor/libressl/tests/quictest.bat +27 -0
  201. data/vendor/libressl/tests/quictest.sh +30 -0
  202. data/vendor/libressl/tests/renegotiation_test.bat +27 -0
  203. data/vendor/libressl/tests/renegotiation_test.sh +30 -0
  204. data/vendor/libressl/tests/rfc5280time_small.test +10 -0
  205. data/vendor/libressl/tests/servertest.bat +27 -0
  206. data/vendor/libressl/tests/servertest.sh +30 -0
  207. data/vendor/libressl/tests/shutdowntest.bat +27 -0
  208. data/vendor/libressl/tests/shutdowntest.sh +30 -0
  209. data/vendor/libressl/tests/ssltest.bat +32 -0
  210. data/vendor/libressl/tests/ssltest.sh +48 -0
  211. data/vendor/libressl/tests/testdsa.bat +47 -0
  212. data/vendor/libressl/tests/testdsa.sh +57 -0
  213. data/vendor/libressl/tests/testenc.bat +85 -0
  214. data/vendor/libressl/tests/testenc.sh +93 -0
  215. data/vendor/libressl/tests/testrsa.bat +47 -0
  216. data/vendor/libressl/tests/testrsa.sh +57 -0
  217. data/vendor/libressl/tests/testssl.bat +171 -0
  218. data/vendor/libressl/tests/tlstest.bat +27 -0
  219. data/vendor/libressl/tests/tlstest.sh +28 -0
  220. data/vendor/libressl/tls/CMakeLists.txt +125 -0
  221. data/vendor/libressl/tls/Makefile.am +76 -0
  222. data/vendor/libressl/tls/compat/ftruncate.c +17 -0
  223. data/vendor/libressl/tls/compat/pread.c +29 -0
  224. data/vendor/libressl/tls/compat/pwrite.c +29 -0
  225. data/vendor/libressl/update.sh +460 -0
  226. data/vendor/liburing/.github/workflows/ci.yml +8 -0
  227. data/vendor/liburing/configure +23 -2
  228. data/vendor/liburing/examples/helpers.c +1 -1
  229. data/vendor/liburing/examples/helpers.h +1 -1
  230. data/vendor/liburing/examples/reg-wait.c +3 -3
  231. data/vendor/liburing/examples/zcrx.c +5 -5
  232. data/vendor/liburing/liburing.spec +1 -1
  233. data/vendor/liburing/src/include/liburing/io_uring.h +16 -0
  234. data/vendor/liburing/src/include/liburing.h +20 -4
  235. data/vendor/liburing/src/lib.h +2 -4
  236. data/vendor/liburing/src/liburing-ffi.map +7 -0
  237. data/vendor/liburing/src/liburing.map +7 -0
  238. data/vendor/liburing/src/register.c +5 -0
  239. data/vendor/liburing/src/sanitize.c +5 -4
  240. data/vendor/liburing/src/setup.c +43 -28
  241. data/vendor/liburing/test/Makefile +7 -0
  242. data/vendor/liburing/test/cmd-discard.c +2 -2
  243. data/vendor/liburing/test/evfd-short-read.c +84 -0
  244. data/vendor/liburing/test/fdinfo-sqpoll.c +117 -0
  245. data/vendor/liburing/test/fdinfo.c +1 -1
  246. data/vendor/liburing/test/fixed-buf-merge.c +2 -2
  247. data/vendor/liburing/test/futex-kill.c +135 -0
  248. data/vendor/liburing/test/helpers.c +1 -1
  249. data/vendor/liburing/test/helpers.h +1 -1
  250. data/vendor/liburing/test/init-mem.c +50 -12
  251. data/vendor/liburing/test/io_uring_passthrough.c +25 -6
  252. data/vendor/liburing/test/msg-ring.c +123 -9
  253. data/vendor/liburing/test/recv-bundle-short-ooo.c +16 -1
  254. data/vendor/liburing/test/recv-inc-ooo.c +411 -0
  255. data/vendor/liburing/test/recv-mshot-fair.c +513 -0
  256. data/vendor/liburing/test/reg-wait.c +14 -14
  257. data/vendor/liburing/test/send-zerocopy.c +4 -4
  258. data/vendor/liburing/test/timerfd-short-read.c +81 -0
  259. data/vendor/liburing/test/timestamp.c +382 -0
  260. data/vendor/liburing/test/zcrx.c +22 -22
  261. metadata +222 -2
@@ -0,0 +1,411 @@
1
+ /* SPDX-License-Identifier: MIT */
2
+ /*
3
+ * Description: Run recv multishot with bundle support and using
4
+ * incrementally consumed buffers, and verify that the
5
+ * ordering is correct.
6
+ *
7
+ * Also see:
8
+ *
9
+ * https://github.com/axboe/liburing/issues/1432
10
+ *
11
+ * for the bug report, and where this test case came from.
12
+ */
13
+ #include <stdio.h>
14
+ #include <stdlib.h>
15
+ #include <string.h>
16
+ #include <unistd.h>
17
+ #include <assert.h>
18
+ #include <sys/socket.h>
19
+ #include <sys/types.h>
20
+ #include <sys/mman.h>
21
+ #include <netinet/in.h>
22
+ #include <arpa/inet.h>
23
+
24
+ #include "liburing.h"
25
+ #include "helpers.h"
26
+
27
+ static int no_buf_ring, no_recv_mshot;
28
+
29
+ /* Configuration constants */
30
+ #define TWO_KB (1024 * 2) /* Size of test data (2KB) */
31
+ #define BUFFER_SIZE 1024 /* Size of each buffer in bytes */
32
+
33
+ #define BUFFER_COUNT 4 /* Number of buffers in the ring */
34
+ #define QUEUE_DEPTH 16 /* io_uring queue depth */
35
+
36
+ #define min(a, b) (((a) < (b)) ? (a) : (b))
37
+
38
+ /**
39
+ * Buffer data structure
40
+ * Contains information about a buffer from the ring
41
+ */
42
+ struct buf_data {
43
+ void *addr; /* Buffer memory address */
44
+ uint32_t len; /* Length of valid data in the buffer */
45
+ };
46
+
47
+ /**
48
+ * Buffer ring data structure
49
+ * Holds information needed to manage a buffer ring
50
+ */
51
+ struct buf_ring_data {
52
+ struct io_uring_buf_ring *buf_ring; /* The io_uring buffer ring */
53
+ void *buffer_memory; /* Memory for all buffers */
54
+ uint16_t ring_entries; /* Number of entries in the ring */
55
+ uint32_t buf_size; /* Size of each buffer */
56
+ };
57
+
58
+ struct read_buf {
59
+ void *buffer_memory; /* Memory for all buffers */
60
+ size_t cursor;
61
+ };
62
+
63
+ /**
64
+ * Sets up and initializes the buffer ring for io_uring
65
+ *
66
+ * This function allocates memory for the buffer ring and all individual buffers,
67
+ * initializes the buffer ring, registers it with io_uring, and adds all buffers
68
+ * to the ring.
69
+ *
70
+ * @param ring Pointer to the io_uring instance
71
+ * @param entries Number of buffer entries to create
72
+ * @param buf_size Size of each buffer in bytes
73
+ * @param bgid Buffer group ID to use
74
+ *
75
+ */
76
+ static int setup_buf_ring(struct buf_ring_data *data, struct io_uring *ring,
77
+ uint16_t entries, uint32_t buf_size, int bgid)
78
+ {
79
+ data->ring_entries = entries;
80
+ data->buf_size = buf_size;
81
+
82
+ /* Allocate page-aligned memory for all buffers */
83
+ size_t total_size = entries * buf_size;
84
+ int page_size = sysconf(_SC_PAGESIZE);
85
+ size_t aligned_size = (total_size + page_size - 1) & ~(page_size - 1);
86
+
87
+ void *buffer_memory = mmap(NULL, aligned_size, PROT_READ | PROT_WRITE,
88
+ MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
89
+ assert(buffer_memory != MAP_FAILED);
90
+
91
+ /* Verify buffer memory is page-aligned as guaranteed by mmap */
92
+ data->buffer_memory = buffer_memory;
93
+
94
+ /* Allocate and setup buffer ring with page alignment */
95
+ void *mapped;
96
+ struct io_uring_buf_ring *buf_ring;
97
+ int ring_size = entries * sizeof(struct io_uring_buf);
98
+
99
+ /* Round up ring size to page boundary */
100
+ ring_size = (ring_size + page_size - 1) & ~(page_size - 1);
101
+
102
+ mapped = mmap(NULL, ring_size, PROT_READ | PROT_WRITE,
103
+ MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
104
+ assert(mapped != MAP_FAILED);
105
+
106
+ buf_ring = (struct io_uring_buf_ring *)mapped;
107
+
108
+ /* Initialize the buffer ring structure */
109
+ io_uring_buf_ring_init(buf_ring);
110
+ data->buf_ring = buf_ring;
111
+
112
+ /* Prepare registration parameters */
113
+ struct io_uring_buf_reg reg = {
114
+ .ring_addr = (unsigned long)buf_ring,
115
+ .ring_entries = entries,
116
+ .bgid = 0
117
+ };
118
+
119
+ /* Register the buffer ring with io_uring */
120
+ int ret = io_uring_register_buf_ring(ring, &reg, IOU_PBUF_RING_INC);
121
+
122
+ if (ret) {
123
+ if (ret == -EINVAL) {
124
+ no_buf_ring = 1;
125
+ return T_EXIT_SKIP;
126
+ }
127
+ fprintf(stderr, "Buffer ring setup: %d\n", ret);
128
+ return T_EXIT_FAIL;
129
+ }
130
+
131
+ /* Add all individual buffers to the ring */
132
+ for (int i = 0; i < entries; i++) {
133
+ void *buf_addr = buffer_memory + i * buf_size;
134
+
135
+ io_uring_buf_ring_add(buf_ring, buf_addr, buf_size, i,
136
+ io_uring_buf_ring_mask(entries), i);
137
+ }
138
+
139
+ /* Make all buffers available by advancing the tail pointer */
140
+ io_uring_buf_ring_advance(buf_ring, entries);
141
+ return T_EXIT_PASS;
142
+ }
143
+
144
+ /**
145
+ * Verifies that received buffer data matches expected data
146
+ *
147
+ * This function compares each byte of received data against the expected data
148
+ * and asserts if any mismatch is found. It also prints the comparison for debugging.
149
+ *
150
+ * @param buf Pointer to buffer containing received data
151
+ * @param expected_data_start Pointer to start of expected data for comparison
152
+ */
153
+ static int verify_received_buffer(struct buf_data *buf, uint8_t *expected_data_start)
154
+ {
155
+ uint8_t *data = buf->addr;
156
+
157
+ for (uint32_t i = 0; i < buf->len; i++) {
158
+ if (data[i] != expected_data_start[i]) {
159
+ fprintf(stderr, "Recv data ordering mismatch. expected: %d, get: %d\n", expected_data_start[i], data[i]);
160
+ return 1;
161
+ }
162
+ }
163
+
164
+ return 0;
165
+ }
166
+
167
+ /**
168
+ * Processes a completed io_uring receive operation
169
+ *
170
+ * This function handles the completion queue entry by:
171
+ * 1. Extracting the received data from the CQE
172
+ * 2. Verifying the data matches the expected pattern
173
+ *
174
+ * @param cqe Completion queue entry to process
175
+ * @param rb read_buf data struct to keep track the cursor
176
+ * @param current_expect Pointer to current position in expected data (updated by this function)
177
+ */
178
+ static int process_completion(struct io_uring_cqe *cqe, struct read_buf *rb,
179
+ uint8_t **current_expect)
180
+ {
181
+ usleep(1);
182
+
183
+ if (cqe->res <= 0) {
184
+ /* Handle error or EOF condition */
185
+ if (cqe->res == 0) {
186
+ fprintf(stderr, "EOF reached\n");
187
+ } else if (cqe->res == -EINVAL) {
188
+ /* no recv mshot support */
189
+ no_recv_mshot = 1;
190
+ } else if (cqe->res != -ENOBUFS) {
191
+ fprintf(stderr, "CQE res %d\n", cqe->res);
192
+ return 1;
193
+ }
194
+ return 0;
195
+ }
196
+
197
+ /* Extract data length from completion */
198
+ uint32_t total_len = cqe->res;
199
+
200
+ /* should never get a len large then bundled buffer size */
201
+ assert(total_len <= BUFFER_SIZE);
202
+
203
+ void *buffer_addr = (uint8_t*)rb->buffer_memory + (rb->cursor);
204
+ /* Prepare buffer data structure for verification */
205
+ struct buf_data buf = {
206
+ .addr = buffer_addr,
207
+ .len = total_len
208
+ };
209
+
210
+ /* Verify received data against expected pattern */
211
+ if (verify_received_buffer(&buf, *current_expect))
212
+ return T_EXIT_FAIL;
213
+ rb->cursor += total_len;
214
+ return 0;
215
+ }
216
+
217
+ /**
218
+ * Writes all the data to the specified file descriptor
219
+ *
220
+ * This function ensures that all data is written, handling partial writes
221
+ * by making repeated calls to write() until all bytes are sent.
222
+ *
223
+ * @param fd File descriptor to write to
224
+ * @param data Pointer to the data buffer to write
225
+ * @param size Number of bytes to write
226
+ */
227
+ static void write_all(int fd, const void *data, size_t size)
228
+ {
229
+ const uint8_t *buf = data;
230
+ size_t bytes_sent = 0;
231
+
232
+ /* Continue until all data is sent */
233
+ while (bytes_sent < size) {
234
+ ssize_t sent;
235
+
236
+ sent = write(fd, buf + bytes_sent, size - bytes_sent);
237
+ assert(sent > 0); /* Ensure write succeeded */
238
+ bytes_sent += sent;
239
+ }
240
+ }
241
+
242
+ /**
243
+ * Main test function for io_uring bundle receive mechanism
244
+ *
245
+ * This function demonstrates the complete flow of using io_uring's buffer ring
246
+ * and multishot receive with IORING_RECVSEND_BUNDLE flag. It performs these steps:
247
+ * 1. Set up an io_uring instance and buffer ring
248
+ * 2. Create a TCP socket pair for testing
249
+ * 3. Send 2KB of pattern data over the socket
250
+ * 4. Receive and verify the data are as expected
251
+ *
252
+ */
253
+ static int test_recv_incr(int queue_flags)
254
+ {
255
+ /* Initialize io_uring with parameters */
256
+ struct io_uring ring;
257
+ struct io_uring_params params = { .flags = queue_flags, };
258
+ int ret, eret;
259
+
260
+ ret = t_create_ring_params(QUEUE_DEPTH, &ring, &params);
261
+ if (ret == T_SETUP_SKIP)
262
+ return T_EXIT_SKIP;
263
+ else if (ret != T_SETUP_OK)
264
+ return T_EXIT_FAIL;
265
+
266
+ /* Set up the buffer ring for receiving data */
267
+ struct buf_ring_data br_data;
268
+ ret = setup_buf_ring(&br_data, &ring, BUFFER_COUNT, BUFFER_SIZE, 0);
269
+ if (ret == T_EXIT_SKIP)
270
+ return T_EXIT_SKIP;
271
+ else if (ret != T_EXIT_PASS)
272
+ return T_EXIT_FAIL;
273
+
274
+ /* Create socket pair for local communication testing */
275
+ int socket_fds[2];
276
+ ret = t_create_socket_pair(socket_fds, true);
277
+ assert(ret == 0);
278
+
279
+ int receiver_fd = socket_fds[0];
280
+ int sender_fd = socket_fds[1];
281
+
282
+ size_t data_received = 0; /* Tracks total bytes received */
283
+
284
+ /* Submit initial multishot receive operations with buffer selection */
285
+ struct io_uring_sqe *sqe = io_uring_get_sqe(&ring);
286
+
287
+ io_uring_prep_recv_multishot(sqe, receiver_fd, NULL, 0, 0);
288
+ sqe->flags |= IOSQE_BUFFER_SELECT;
289
+ sqe->ioprio |= IORING_RECVSEND_BUNDLE;
290
+ sqe->buf_group = 0;
291
+ io_uring_submit(&ring);
292
+
293
+ /* Allocate and initialize test data with pattern */
294
+ size_t total_bytes = TWO_KB;
295
+
296
+ uint8_t *test_data = malloc(total_bytes);
297
+ for (int i = 0; i < total_bytes; i++)
298
+ test_data[i] = i % 256; /* Create repeating pattern */
299
+
300
+ /* Send data in chunks to test buffer boundary handling, intentionally misaligned with buffer size */
301
+ size_t chunk_sizes[] = {512, 333, 777, 426};
302
+ size_t sent_offset = 0;
303
+ size_t num_chunks = sizeof(chunk_sizes) / sizeof(chunk_sizes[0]);
304
+
305
+ struct read_buf rb = {
306
+ .buffer_memory = br_data.buffer_memory,
307
+ .cursor = 0
308
+ };
309
+
310
+ for (size_t i = 0; i < num_chunks; i++) {
311
+ size_t chunk_size = chunk_sizes[i];
312
+ size_t end_offset = min(sent_offset + chunk_size, total_bytes);
313
+ size_t chunk_len = end_offset - sent_offset;
314
+ uint8_t* chunk = test_data + sent_offset;
315
+
316
+ /* Send test data through the socket */
317
+ write_all(sender_fd, chunk, chunk_len);
318
+
319
+ struct io_uring_cqe *cqe;
320
+
321
+ size_t remaining_chunk_len = chunk_len;
322
+
323
+ while (remaining_chunk_len) {
324
+ /* Wait for a completion event */
325
+ ret = io_uring_wait_cqe(&ring, &cqe);
326
+ if (ret) {
327
+ fprintf(stderr, "wait_cqe=%d\n", ret);
328
+ eret = T_EXIT_FAIL;
329
+ goto exit;
330
+ }
331
+
332
+ /* Initialize pointer to track our position in expected data */
333
+ uint8_t *current_expect = chunk + (chunk_len - remaining_chunk_len);
334
+
335
+ if (process_completion(cqe, &rb, &current_expect)) {
336
+ eret = T_EXIT_FAIL;
337
+ goto exit;
338
+ }
339
+ if (no_recv_mshot) {
340
+ eret = T_EXIT_SKIP;
341
+ goto exit;
342
+ }
343
+
344
+ remaining_chunk_len -= cqe->res;
345
+ data_received += cqe->res;
346
+
347
+ io_uring_cq_advance(&ring, 1);
348
+ }
349
+ sent_offset = end_offset;
350
+ if (sent_offset >= total_bytes)
351
+ break;
352
+ }
353
+
354
+ /* Close sender side to signal EOF to receiver */
355
+ close(sender_fd);
356
+
357
+ /* Verify we received all expected data */
358
+ if (data_received != total_bytes) {
359
+ fprintf(stderr, "Received %u, wanted %u\n", (int) data_received, TWO_KB);
360
+ return T_EXIT_FAIL;
361
+ }
362
+
363
+ eret = T_EXIT_PASS;
364
+ exit:
365
+ /* Clean up all allocated resources */
366
+ close(receiver_fd); /* Close socket */
367
+ io_uring_queue_exit(&ring); /* Clean up io_uring */
368
+
369
+ /* Free memory resources */
370
+ munmap(br_data.buffer_memory, BUFFER_COUNT * BUFFER_SIZE);
371
+ munmap(br_data.buf_ring, BUFFER_COUNT * sizeof(struct io_uring_buf));
372
+ free(test_data);
373
+
374
+ return eret;
375
+ }
376
+
377
+ int main(int argc, char *argv[])
378
+ {
379
+ int ret;
380
+
381
+ if (argc > 1)
382
+ return T_EXIT_SKIP;
383
+
384
+ ret = test_recv_incr(0);
385
+ if (ret == T_EXIT_FAIL) {
386
+ fprintf(stderr, "test 0 failed\n");
387
+ return ret;
388
+ }
389
+ if (no_buf_ring || no_recv_mshot)
390
+ return T_EXIT_SKIP;
391
+
392
+ ret = test_recv_incr(IORING_SETUP_SINGLE_ISSUER | IORING_SETUP_DEFER_TASKRUN);
393
+ if (ret == T_EXIT_FAIL) {
394
+ fprintf(stderr, "test defer failed\n");
395
+ return ret;
396
+ }
397
+
398
+ ret = test_recv_incr(IORING_SETUP_SQPOLL);
399
+ if (ret == T_EXIT_FAIL) {
400
+ fprintf(stderr, "test sqpoll failed\n");
401
+ return ret;
402
+ }
403
+
404
+ ret = test_recv_incr(IORING_SETUP_COOP_TASKRUN);
405
+ if (ret == T_EXIT_FAIL) {
406
+ fprintf(stderr, "test coop failed\n");
407
+ return ret;
408
+ }
409
+
410
+ return T_EXIT_PASS;
411
+ }