polyphony 0.94 → 0.95

Sign up to get free protection for your applications and to get access to all the features.
Files changed (306) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/test.yml +2 -2
  3. data/.gitignore +3 -3
  4. data/CHANGELOG.md +14 -0
  5. data/docs/api-reference/fiber.md +2 -2
  6. data/docs/api-reference/object.md +3 -3
  7. data/docs/main-concepts/exception-handling.md +2 -2
  8. data/ext/polyphony/backend_common.c +3 -3
  9. data/ext/polyphony/backend_io_uring.c +18 -16
  10. data/ext/polyphony/event.c +1 -1
  11. data/ext/polyphony/extconf.rb +5 -3
  12. data/ext/polyphony/fiber.c +5 -13
  13. data/ext/polyphony/io_extensions.c +1 -1
  14. data/ext/polyphony/pipe.c +1 -1
  15. data/ext/polyphony/polyphony.c +1 -1
  16. data/ext/polyphony/polyphony_ext.c +1 -1
  17. data/ext/polyphony/queue.c +1 -1
  18. data/ext/polyphony/ring_buffer.c +1 -0
  19. data/ext/polyphony/socket_extensions.c +1 -1
  20. data/ext/polyphony/thread.c +1 -1
  21. data/lib/polyphony/extensions/enumerator.rb +16 -0
  22. data/lib/polyphony/extensions/socket.rb +2 -0
  23. data/lib/polyphony/extensions.rb +1 -0
  24. data/lib/polyphony/version.rb +1 -1
  25. data/polyphony.gemspec +2 -2
  26. data/test/test_backend.rb +5 -1
  27. data/test/test_enumerator.rb +46 -0
  28. data/test/test_io.rb +241 -216
  29. data/test/test_socket.rb +1 -1
  30. data/test/test_thread_pool.rb +3 -3
  31. data/vendor/liburing/.github/workflows/build.yml +51 -5
  32. data/vendor/liburing/.github/workflows/shellcheck.yml +1 -1
  33. data/vendor/liburing/.gitignore +6 -123
  34. data/vendor/liburing/CHANGELOG +35 -0
  35. data/vendor/liburing/CITATION.cff +11 -0
  36. data/vendor/liburing/LICENSE +16 -3
  37. data/vendor/liburing/Makefile +3 -1
  38. data/vendor/liburing/Makefile.common +1 -0
  39. data/vendor/liburing/README +14 -2
  40. data/vendor/liburing/SECURITY.md +6 -0
  41. data/vendor/liburing/configure +16 -15
  42. data/vendor/liburing/examples/Makefile +4 -1
  43. data/vendor/liburing/examples/io_uring-udp.c +395 -0
  44. data/vendor/liburing/examples/poll-bench.c +101 -0
  45. data/vendor/liburing/examples/send-zerocopy.c +339 -0
  46. data/vendor/liburing/liburing.spec +1 -1
  47. data/vendor/liburing/man/io_uring.7 +38 -11
  48. data/vendor/liburing/man/io_uring_buf_ring_add.3 +53 -0
  49. data/vendor/liburing/man/io_uring_buf_ring_advance.3 +31 -0
  50. data/vendor/liburing/man/io_uring_buf_ring_cq_advance.3 +41 -0
  51. data/vendor/liburing/man/io_uring_buf_ring_init.3 +30 -0
  52. data/vendor/liburing/man/io_uring_buf_ring_mask.3 +27 -0
  53. data/vendor/liburing/man/io_uring_cq_advance.3 +29 -15
  54. data/vendor/liburing/man/io_uring_cq_has_overflow.3 +25 -0
  55. data/vendor/liburing/man/io_uring_cq_ready.3 +9 -8
  56. data/vendor/liburing/man/io_uring_cqe_get_data.3 +32 -13
  57. data/vendor/liburing/man/io_uring_cqe_get_data64.3 +1 -0
  58. data/vendor/liburing/man/io_uring_cqe_seen.3 +22 -12
  59. data/vendor/liburing/man/io_uring_enter.2 +249 -32
  60. data/vendor/liburing/man/io_uring_enter2.2 +1 -0
  61. data/vendor/liburing/man/io_uring_free_probe.3 +11 -8
  62. data/vendor/liburing/man/io_uring_get_events.3 +33 -0
  63. data/vendor/liburing/man/io_uring_get_probe.3 +9 -8
  64. data/vendor/liburing/man/io_uring_get_sqe.3 +29 -10
  65. data/vendor/liburing/man/io_uring_opcode_supported.3 +11 -10
  66. data/vendor/liburing/man/io_uring_peek_cqe.3 +38 -0
  67. data/vendor/liburing/man/io_uring_prep_accept.3 +197 -0
  68. data/vendor/liburing/man/io_uring_prep_accept_direct.3 +1 -0
  69. data/vendor/liburing/man/io_uring_prep_cancel.3 +118 -0
  70. data/vendor/liburing/man/io_uring_prep_cancel64.3 +1 -0
  71. data/vendor/liburing/man/io_uring_prep_close.3 +59 -0
  72. data/vendor/liburing/man/io_uring_prep_close_direct.3 +1 -0
  73. data/vendor/liburing/man/io_uring_prep_connect.3 +66 -0
  74. data/vendor/liburing/man/io_uring_prep_fadvise.3 +59 -0
  75. data/vendor/liburing/man/io_uring_prep_fallocate.3 +59 -0
  76. data/vendor/liburing/man/io_uring_prep_files_update.3 +92 -0
  77. data/vendor/liburing/man/io_uring_prep_fsync.3 +70 -0
  78. data/vendor/liburing/man/io_uring_prep_link.3 +1 -0
  79. data/vendor/liburing/man/io_uring_prep_linkat.3 +91 -0
  80. data/vendor/liburing/man/io_uring_prep_madvise.3 +56 -0
  81. data/vendor/liburing/man/io_uring_prep_mkdir.3 +1 -0
  82. data/vendor/liburing/man/io_uring_prep_mkdirat.3 +83 -0
  83. data/vendor/liburing/man/io_uring_prep_msg_ring.3 +39 -25
  84. data/vendor/liburing/man/io_uring_prep_multishot_accept.3 +1 -0
  85. data/vendor/liburing/man/io_uring_prep_multishot_accept_direct.3 +1 -0
  86. data/vendor/liburing/man/io_uring_prep_nop.3 +28 -0
  87. data/vendor/liburing/man/io_uring_prep_openat.3 +117 -0
  88. data/vendor/liburing/man/io_uring_prep_openat2.3 +117 -0
  89. data/vendor/liburing/man/io_uring_prep_openat2_direct.3 +1 -0
  90. data/vendor/liburing/man/io_uring_prep_openat_direct.3 +1 -0
  91. data/vendor/liburing/man/io_uring_prep_poll_add.3 +72 -0
  92. data/vendor/liburing/man/io_uring_prep_poll_multishot.3 +1 -0
  93. data/vendor/liburing/man/io_uring_prep_poll_remove.3 +55 -0
  94. data/vendor/liburing/man/io_uring_prep_poll_update.3 +89 -0
  95. data/vendor/liburing/man/io_uring_prep_provide_buffers.3 +131 -0
  96. data/vendor/liburing/man/io_uring_prep_read.3 +33 -14
  97. data/vendor/liburing/man/io_uring_prep_read_fixed.3 +39 -21
  98. data/vendor/liburing/man/io_uring_prep_readv.3 +49 -15
  99. data/vendor/liburing/man/io_uring_prep_readv2.3 +49 -17
  100. data/vendor/liburing/man/io_uring_prep_recv.3 +105 -0
  101. data/vendor/liburing/man/io_uring_prep_recv_multishot.3 +1 -0
  102. data/vendor/liburing/man/io_uring_prep_recvmsg.3 +124 -0
  103. data/vendor/liburing/man/io_uring_prep_recvmsg_multishot.3 +1 -0
  104. data/vendor/liburing/man/io_uring_prep_remove_buffers.3 +52 -0
  105. data/vendor/liburing/man/io_uring_prep_rename.3 +1 -0
  106. data/vendor/liburing/man/io_uring_prep_renameat.3 +96 -0
  107. data/vendor/liburing/man/io_uring_prep_send.3 +57 -0
  108. data/vendor/liburing/man/io_uring_prep_send_zc.3 +64 -0
  109. data/vendor/liburing/man/io_uring_prep_sendmsg.3 +69 -0
  110. data/vendor/liburing/man/io_uring_prep_shutdown.3 +53 -0
  111. data/vendor/liburing/man/io_uring_prep_socket.3 +118 -0
  112. data/vendor/liburing/man/io_uring_prep_socket_direct.3 +1 -0
  113. data/vendor/liburing/man/io_uring_prep_socket_direct_alloc.3 +1 -0
  114. data/vendor/liburing/man/io_uring_prep_splice.3 +80 -0
  115. data/vendor/liburing/man/io_uring_prep_statx.3 +74 -0
  116. data/vendor/liburing/man/io_uring_prep_symlink.3 +1 -0
  117. data/vendor/liburing/man/io_uring_prep_symlinkat.3 +85 -0
  118. data/vendor/liburing/man/io_uring_prep_sync_file_range.3 +59 -0
  119. data/vendor/liburing/man/io_uring_prep_tee.3 +74 -0
  120. data/vendor/liburing/man/io_uring_prep_timeout.3 +95 -0
  121. data/vendor/liburing/man/io_uring_prep_timeout_remove.3 +1 -0
  122. data/vendor/liburing/man/io_uring_prep_timeout_update.3 +98 -0
  123. data/vendor/liburing/man/io_uring_prep_unlink.3 +1 -0
  124. data/vendor/liburing/man/io_uring_prep_unlinkat.3 +82 -0
  125. data/vendor/liburing/man/io_uring_prep_write.3 +32 -15
  126. data/vendor/liburing/man/io_uring_prep_write_fixed.3 +39 -21
  127. data/vendor/liburing/man/io_uring_prep_writev.3 +50 -16
  128. data/vendor/liburing/man/io_uring_prep_writev2.3 +50 -17
  129. data/vendor/liburing/man/io_uring_queue_exit.3 +3 -4
  130. data/vendor/liburing/man/io_uring_queue_init.3 +58 -13
  131. data/vendor/liburing/man/io_uring_queue_init_params.3 +1 -0
  132. data/vendor/liburing/man/io_uring_recvmsg_cmsg_firsthdr.3 +1 -0
  133. data/vendor/liburing/man/io_uring_recvmsg_cmsg_nexthdr.3 +1 -0
  134. data/vendor/liburing/man/io_uring_recvmsg_name.3 +1 -0
  135. data/vendor/liburing/man/io_uring_recvmsg_out.3 +78 -0
  136. data/vendor/liburing/man/io_uring_recvmsg_payload.3 +1 -0
  137. data/vendor/liburing/man/io_uring_recvmsg_payload_length.3 +1 -0
  138. data/vendor/liburing/man/io_uring_recvmsg_validate.3 +1 -0
  139. data/vendor/liburing/man/io_uring_register.2 +153 -13
  140. data/vendor/liburing/man/io_uring_register_buf_ring.3 +140 -0
  141. data/vendor/liburing/man/io_uring_register_buffers.3 +32 -12
  142. data/vendor/liburing/man/io_uring_register_eventfd.3 +51 -0
  143. data/vendor/liburing/man/io_uring_register_eventfd_async.3 +1 -0
  144. data/vendor/liburing/man/io_uring_register_file_alloc_range.3 +52 -0
  145. data/vendor/liburing/man/io_uring_register_files.3 +33 -11
  146. data/vendor/liburing/man/io_uring_register_files_sparse.3 +1 -0
  147. data/vendor/liburing/man/io_uring_register_iowq_aff.3 +61 -0
  148. data/vendor/liburing/man/io_uring_register_iowq_max_workers.3 +71 -0
  149. data/vendor/liburing/man/io_uring_register_ring_fd.3 +49 -0
  150. data/vendor/liburing/man/io_uring_register_sync_cancel.3 +71 -0
  151. data/vendor/liburing/man/io_uring_setup.2 +119 -13
  152. data/vendor/liburing/man/io_uring_sq_ready.3 +14 -8
  153. data/vendor/liburing/man/io_uring_sq_space_left.3 +9 -9
  154. data/vendor/liburing/man/io_uring_sqe_set_data.3 +29 -11
  155. data/vendor/liburing/man/io_uring_sqe_set_data64.3 +1 -0
  156. data/vendor/liburing/man/io_uring_sqe_set_flags.3 +38 -11
  157. data/vendor/liburing/man/io_uring_sqring_wait.3 +13 -9
  158. data/vendor/liburing/man/io_uring_submit.3 +29 -12
  159. data/vendor/liburing/man/io_uring_submit_and_get_events.3 +31 -0
  160. data/vendor/liburing/man/io_uring_submit_and_wait.3 +16 -12
  161. data/vendor/liburing/man/io_uring_submit_and_wait_timeout.3 +30 -23
  162. data/vendor/liburing/man/io_uring_unregister_buf_ring.3 +30 -0
  163. data/vendor/liburing/man/io_uring_unregister_buffers.3 +11 -10
  164. data/vendor/liburing/man/io_uring_unregister_eventfd.3 +1 -0
  165. data/vendor/liburing/man/io_uring_unregister_files.3 +11 -10
  166. data/vendor/liburing/man/io_uring_unregister_iowq_aff.3 +1 -0
  167. data/vendor/liburing/man/io_uring_unregister_ring_fd.3 +32 -0
  168. data/vendor/liburing/man/io_uring_wait_cqe.3 +19 -12
  169. data/vendor/liburing/man/io_uring_wait_cqe_nr.3 +21 -14
  170. data/vendor/liburing/man/io_uring_wait_cqe_timeout.3 +27 -13
  171. data/vendor/liburing/man/io_uring_wait_cqes.3 +24 -14
  172. data/vendor/liburing/src/Makefile +8 -7
  173. data/vendor/liburing/src/arch/aarch64/lib.h +48 -0
  174. data/vendor/liburing/src/arch/aarch64/syscall.h +0 -4
  175. data/vendor/liburing/src/arch/generic/lib.h +0 -4
  176. data/vendor/liburing/src/arch/generic/syscall.h +29 -16
  177. data/vendor/liburing/src/arch/syscall-defs.h +41 -14
  178. data/vendor/liburing/src/arch/x86/lib.h +0 -21
  179. data/vendor/liburing/src/arch/x86/syscall.h +146 -10
  180. data/vendor/liburing/src/include/liburing/io_uring.h +245 -5
  181. data/vendor/liburing/src/include/liburing.h +468 -35
  182. data/vendor/liburing/src/int_flags.h +1 -0
  183. data/vendor/liburing/src/lib.h +20 -16
  184. data/vendor/liburing/src/liburing.map +16 -0
  185. data/vendor/liburing/src/nolibc.c +1 -1
  186. data/vendor/liburing/src/queue.c +87 -55
  187. data/vendor/liburing/src/register.c +129 -53
  188. data/vendor/liburing/src/setup.c +65 -28
  189. data/vendor/liburing/src/syscall.c +14 -32
  190. data/vendor/liburing/src/syscall.h +12 -64
  191. data/vendor/liburing/test/{232c93d07b74-test.c → 232c93d07b74.c} +8 -9
  192. data/vendor/liburing/test/{35fa71a030ca-test.c → 35fa71a030ca.c} +4 -4
  193. data/vendor/liburing/test/{500f9fbadef8-test.c → 500f9fbadef8.c} +7 -7
  194. data/vendor/liburing/test/{7ad0e4b2f83c-test.c → 7ad0e4b2f83c.c} +8 -7
  195. data/vendor/liburing/test/{8a9973408177-test.c → 8a9973408177.c} +4 -3
  196. data/vendor/liburing/test/{917257daa0fe-test.c → 917257daa0fe.c} +3 -2
  197. data/vendor/liburing/test/Makefile +60 -62
  198. data/vendor/liburing/test/{a0908ae19763-test.c → a0908ae19763.c} +3 -2
  199. data/vendor/liburing/test/{a4c0b3decb33-test.c → a4c0b3decb33.c} +3 -2
  200. data/vendor/liburing/test/accept-link.c +5 -4
  201. data/vendor/liburing/test/accept-reuse.c +17 -16
  202. data/vendor/liburing/test/accept-test.c +14 -10
  203. data/vendor/liburing/test/accept.c +529 -107
  204. data/vendor/liburing/test/across-fork.c +7 -6
  205. data/vendor/liburing/test/{b19062a56726-test.c → b19062a56726.c} +3 -2
  206. data/vendor/liburing/test/{b5837bd5311d-test.c → b5837bd5311d.c} +10 -9
  207. data/vendor/liburing/test/buf-ring.c +420 -0
  208. data/vendor/liburing/test/{ce593a6c480a-test.c → ce593a6c480a.c} +15 -12
  209. data/vendor/liburing/test/connect.c +8 -7
  210. data/vendor/liburing/test/cq-full.c +5 -4
  211. data/vendor/liburing/test/cq-overflow.c +242 -12
  212. data/vendor/liburing/test/cq-peek-batch.c +5 -4
  213. data/vendor/liburing/test/cq-ready.c +5 -4
  214. data/vendor/liburing/test/cq-size.c +5 -4
  215. data/vendor/liburing/test/{d4ae271dfaae-test.c → d4ae271dfaae.c} +2 -2
  216. data/vendor/liburing/test/{d77a67ed5f27-test.c → d77a67ed5f27.c} +6 -6
  217. data/vendor/liburing/test/defer-taskrun.c +336 -0
  218. data/vendor/liburing/test/defer.c +26 -14
  219. data/vendor/liburing/test/double-poll-crash.c +15 -5
  220. data/vendor/liburing/test/drop-submit.c +5 -3
  221. data/vendor/liburing/test/{eeed8b54e0df-test.c → eeed8b54e0df.c} +7 -6
  222. data/vendor/liburing/test/empty-eownerdead.c +4 -4
  223. data/vendor/liburing/test/eventfd-disable.c +48 -20
  224. data/vendor/liburing/test/eventfd-reg.c +10 -9
  225. data/vendor/liburing/test/eventfd-ring.c +13 -12
  226. data/vendor/liburing/test/eventfd.c +13 -12
  227. data/vendor/liburing/test/exit-no-cleanup.c +1 -1
  228. data/vendor/liburing/test/fadvise.c +3 -3
  229. data/vendor/liburing/test/fallocate.c +16 -9
  230. data/vendor/liburing/test/{fc2a85cb02ef-test.c → fc2a85cb02ef.c} +4 -3
  231. data/vendor/liburing/test/fd-pass.c +187 -0
  232. data/vendor/liburing/test/file-register.c +302 -36
  233. data/vendor/liburing/test/file-update.c +62 -4
  234. data/vendor/liburing/test/file-verify.c +6 -2
  235. data/vendor/liburing/test/files-exit-hang-poll.c +11 -25
  236. data/vendor/liburing/test/files-exit-hang-timeout.c +13 -10
  237. data/vendor/liburing/test/fixed-buf-iter.c +115 -0
  238. data/vendor/liburing/test/fixed-link.c +10 -10
  239. data/vendor/liburing/test/fixed-reuse.c +160 -0
  240. data/vendor/liburing/test/fpos.c +6 -3
  241. data/vendor/liburing/test/fsync.c +3 -3
  242. data/vendor/liburing/test/hardlink.c +10 -6
  243. data/vendor/liburing/test/helpers.c +137 -4
  244. data/vendor/liburing/test/helpers.h +27 -0
  245. data/vendor/liburing/test/io-cancel.c +16 -11
  246. data/vendor/liburing/test/io_uring_enter.c +46 -81
  247. data/vendor/liburing/test/io_uring_passthrough.c +451 -0
  248. data/vendor/liburing/test/io_uring_register.c +59 -229
  249. data/vendor/liburing/test/io_uring_setup.c +24 -29
  250. data/vendor/liburing/test/iopoll-leak.c +85 -0
  251. data/vendor/liburing/test/iopoll.c +16 -9
  252. data/vendor/liburing/test/lfs-openat-write.c +3 -1
  253. data/vendor/liburing/test/link-timeout.c +4 -3
  254. data/vendor/liburing/test/link.c +8 -7
  255. data/vendor/liburing/test/madvise.c +2 -2
  256. data/vendor/liburing/test/mkdir.c +9 -5
  257. data/vendor/liburing/test/msg-ring.c +46 -20
  258. data/vendor/liburing/test/multicqes_drain.c +51 -12
  259. data/vendor/liburing/test/nolibc.c +60 -0
  260. data/vendor/liburing/test/nop.c +78 -16
  261. data/vendor/liburing/test/nvme.h +168 -0
  262. data/vendor/liburing/test/open-direct-link.c +188 -0
  263. data/vendor/liburing/test/open-direct-pick.c +180 -0
  264. data/vendor/liburing/test/openat2.c +3 -3
  265. data/vendor/liburing/test/poll-cancel-all.c +472 -0
  266. data/vendor/liburing/test/poll-link.c +9 -18
  267. data/vendor/liburing/test/poll-mshot-overflow.c +162 -0
  268. data/vendor/liburing/test/poll-mshot-update.c +83 -33
  269. data/vendor/liburing/test/pollfree.c +2 -2
  270. data/vendor/liburing/test/read-before-exit.c +112 -0
  271. data/vendor/liburing/test/read-write.c +83 -1
  272. data/vendor/liburing/test/recv-msgall-stream.c +398 -0
  273. data/vendor/liburing/test/recv-msgall.c +265 -0
  274. data/vendor/liburing/test/recv-multishot.c +505 -0
  275. data/vendor/liburing/test/rename.c +2 -5
  276. data/vendor/liburing/test/ring-leak.c +97 -0
  277. data/vendor/liburing/test/ringbuf-read.c +200 -0
  278. data/vendor/liburing/test/rsrc_tags.c +25 -13
  279. data/vendor/liburing/test/runtests-quiet.sh +11 -0
  280. data/vendor/liburing/test/runtests.sh +18 -20
  281. data/vendor/liburing/test/rw_merge_test.c +3 -2
  282. data/vendor/liburing/test/send-zerocopy.c +684 -0
  283. data/vendor/liburing/test/send_recv.c +49 -2
  284. data/vendor/liburing/test/send_recvmsg.c +165 -55
  285. data/vendor/liburing/test/shutdown.c +3 -4
  286. data/vendor/liburing/test/sigfd-deadlock.c +22 -8
  287. data/vendor/liburing/test/single-issuer.c +171 -0
  288. data/vendor/liburing/test/socket-rw-eagain.c +2 -12
  289. data/vendor/liburing/test/socket-rw-offset.c +2 -11
  290. data/vendor/liburing/test/socket-rw.c +2 -11
  291. data/vendor/liburing/test/socket.c +409 -0
  292. data/vendor/liburing/test/sq-poll-dup.c +1 -1
  293. data/vendor/liburing/test/sq-poll-share.c +1 -1
  294. data/vendor/liburing/test/statx.c +2 -2
  295. data/vendor/liburing/test/submit-and-wait.c +108 -0
  296. data/vendor/liburing/test/submit-link-fail.c +5 -3
  297. data/vendor/liburing/test/submit-reuse.c +0 -2
  298. data/vendor/liburing/test/sync-cancel.c +235 -0
  299. data/vendor/liburing/test/test.h +35 -0
  300. data/vendor/liburing/test/timeout-overflow.c +11 -11
  301. data/vendor/liburing/test/timeout.c +7 -7
  302. data/vendor/liburing/test/tty-write-dpoll.c +60 -0
  303. data/vendor/liburing/test/unlink.c +1 -1
  304. data/vendor/liburing/test/xattr.c +425 -0
  305. metadata +143 -22
  306. data/Gemfile.lock +0 -78
@@ -0,0 +1,472 @@
1
+ /* SPDX-License-Identifier: MIT */
2
+ /*
3
+ * Description: Test IORING_ASYNC_CANCEL_{ALL,FD}
4
+ *
5
+ */
6
+ #include <errno.h>
7
+ #include <stdio.h>
8
+ #include <unistd.h>
9
+ #include <stdlib.h>
10
+ #include <string.h>
11
+ #include <poll.h>
12
+
13
+ #include "liburing.h"
14
+
15
+ static int no_cancel_flags;
16
+
17
+ static int test1(struct io_uring *ring, int *fd)
18
+ {
19
+ struct io_uring_sqe *sqe;
20
+ struct io_uring_cqe *cqe;
21
+ int ret, i;
22
+
23
+ for (i = 0; i < 8; i++) {
24
+ sqe = io_uring_get_sqe(ring);
25
+ if (!sqe) {
26
+ fprintf(stderr, "get sqe failed\n");
27
+ return 1;
28
+ }
29
+
30
+ io_uring_prep_poll_add(sqe, fd[0], POLLIN);
31
+ sqe->user_data = i + 1;
32
+ }
33
+
34
+ ret = io_uring_submit(ring);
35
+ if (ret < 8) {
36
+ fprintf(stderr, "sqe submit failed: %d\n", ret);
37
+ return 1;
38
+ }
39
+
40
+ sqe = io_uring_get_sqe(ring);
41
+ if (!sqe) {
42
+ fprintf(stderr, "get sqe failed\n");
43
+ return 1;
44
+ }
45
+
46
+ /*
47
+ * Mark CANCEL_ALL to cancel all matching the key, and use
48
+ * CANCEL_FD to cancel requests matching the specified fd.
49
+ * This should cancel all the pending poll requests on the pipe
50
+ * input.
51
+ */
52
+ io_uring_prep_cancel(sqe, 0, IORING_ASYNC_CANCEL_ALL);
53
+ sqe->cancel_flags |= IORING_ASYNC_CANCEL_FD;
54
+ sqe->fd = fd[0];
55
+ sqe->user_data = 100;
56
+
57
+ ret = io_uring_submit(ring);
58
+ if (ret < 1) {
59
+ fprintf(stderr, "child: sqe submit failed: %d\n", ret);
60
+ return 1;
61
+ }
62
+
63
+ for (i = 0; i < 9; i++) {
64
+ if (no_cancel_flags)
65
+ break;
66
+ ret = io_uring_wait_cqe(ring, &cqe);
67
+ if (ret) {
68
+ fprintf(stderr, "wait=%d\n", ret);
69
+ return 1;
70
+ }
71
+ switch (cqe->user_data) {
72
+ case 100:
73
+ if (cqe->res == -EINVAL) {
74
+ no_cancel_flags = 1;
75
+ break;
76
+ }
77
+ if (cqe->res != 8) {
78
+ fprintf(stderr, "canceled %d\n", cqe->res);
79
+ return 1;
80
+ }
81
+ break;
82
+ case 1 ... 8:
83
+ if (cqe->res != -ECANCELED) {
84
+ fprintf(stderr, "poll res %d\n", cqe->res);
85
+ return 1;
86
+ }
87
+ break;
88
+ default:
89
+ fprintf(stderr, "invalid user_data %lu\n",
90
+ (unsigned long) cqe->user_data);
91
+ return 1;
92
+ }
93
+ io_uring_cqe_seen(ring, cqe);
94
+ }
95
+
96
+ return 0;
97
+ }
98
+
99
+ static int test2(struct io_uring *ring, int *fd)
100
+ {
101
+ struct io_uring_sqe *sqe;
102
+ struct io_uring_cqe *cqe;
103
+ int ret, i, fd2[2];
104
+
105
+ if (pipe(fd2) < 0) {
106
+ perror("pipe");
107
+ return 1;
108
+ }
109
+
110
+ for (i = 0; i < 8; i++) {
111
+ sqe = io_uring_get_sqe(ring);
112
+ if (!sqe) {
113
+ fprintf(stderr, "get sqe failed\n");
114
+ goto err;
115
+ }
116
+
117
+ if (!(i & 1))
118
+ io_uring_prep_poll_add(sqe, fd[0], POLLIN);
119
+ else
120
+ io_uring_prep_poll_add(sqe, fd2[0], POLLIN);
121
+ sqe->user_data = i & 1;
122
+ }
123
+
124
+ ret = io_uring_submit(ring);
125
+ if (ret < 8) {
126
+ fprintf(stderr, "sqe submit failed: %d\n", ret);
127
+ goto err;
128
+ }
129
+
130
+ sqe = io_uring_get_sqe(ring);
131
+ if (!sqe) {
132
+ fprintf(stderr, "get sqe failed\n");
133
+ goto err;
134
+ }
135
+
136
+ /*
137
+ * Mark CANCEL_ALL to cancel all matching the key, and use
138
+ * CANCEL_FD to cancel requests matching the specified fd.
139
+ * This should cancel all the pending poll requests on the pipe
140
+ * input.
141
+ */
142
+ io_uring_prep_cancel(sqe, 0, IORING_ASYNC_CANCEL_ALL);
143
+ sqe->cancel_flags |= IORING_ASYNC_CANCEL_FD;
144
+ sqe->fd = fd[0];
145
+ sqe->user_data = 100;
146
+
147
+ ret = io_uring_submit(ring);
148
+ if (ret < 1) {
149
+ fprintf(stderr, "sqe submit failed: %d\n", ret);
150
+ goto err;
151
+ }
152
+
153
+ for (i = 0; i < 5; i++) {
154
+ ret = io_uring_wait_cqe(ring, &cqe);
155
+ if (ret) {
156
+ fprintf(stderr, "wait=%d\n", ret);
157
+ goto err;
158
+ }
159
+ switch (cqe->user_data) {
160
+ case 100:
161
+ if (cqe->res != 4) {
162
+ fprintf(stderr, "canceled %d\n", cqe->res);
163
+ goto err;
164
+ }
165
+ break;
166
+ case 0:
167
+ if (cqe->res != -ECANCELED) {
168
+ fprintf(stderr, "poll res %d\n", cqe->res);
169
+ goto err;
170
+ }
171
+ break;
172
+ default:
173
+ fprintf(stderr, "invalid user_data %lu\n",
174
+ (unsigned long) cqe->user_data);
175
+ goto err;
176
+ }
177
+ io_uring_cqe_seen(ring, cqe);
178
+ }
179
+
180
+ usleep(1000);
181
+
182
+ /*
183
+ * Should not have any pending CQEs now
184
+ */
185
+ ret = io_uring_peek_cqe(ring, &cqe);
186
+ if (!ret) {
187
+ fprintf(stderr, "Unexpected extra cancel cqe\n");
188
+ goto err;
189
+ }
190
+
191
+ sqe = io_uring_get_sqe(ring);
192
+ if (!sqe) {
193
+ fprintf(stderr, "get sqe failed\n");
194
+ goto err;
195
+ }
196
+
197
+ /*
198
+ * Mark CANCEL_ALL to cancel all matching the key, and use
199
+ * CANCEL_FD to cancel requests matching the specified fd.
200
+ * This should cancel all the pending poll requests on the pipe
201
+ * input.
202
+ */
203
+ io_uring_prep_cancel(sqe, 0, IORING_ASYNC_CANCEL_ALL);
204
+ sqe->cancel_flags |= IORING_ASYNC_CANCEL_FD;
205
+ sqe->fd = fd2[0];
206
+ sqe->user_data = 100;
207
+
208
+ ret = io_uring_submit(ring);
209
+ if (ret < 1) {
210
+ fprintf(stderr, "sqe submit failed: %d\n", ret);
211
+ goto err;
212
+ }
213
+
214
+ for (i = 0; i < 5; i++) {
215
+ ret = io_uring_wait_cqe(ring, &cqe);
216
+ if (ret) {
217
+ fprintf(stderr, "wait=%d\n", ret);
218
+ goto err;
219
+ }
220
+ switch (cqe->user_data) {
221
+ case 100:
222
+ if (cqe->res != 4) {
223
+ fprintf(stderr, "canceled %d\n", cqe->res);
224
+ goto err;
225
+ }
226
+ break;
227
+ case 1:
228
+ if (cqe->res != -ECANCELED) {
229
+ fprintf(stderr, "poll res %d\n", cqe->res);
230
+ goto err;
231
+ }
232
+ break;
233
+ default:
234
+ fprintf(stderr, "invalid user_data %lu\n",
235
+ (unsigned long) cqe->user_data);
236
+ goto err;
237
+ }
238
+ io_uring_cqe_seen(ring, cqe);
239
+ }
240
+
241
+ close(fd2[0]);
242
+ close(fd2[1]);
243
+ return 0;
244
+ err:
245
+ close(fd2[0]);
246
+ close(fd2[1]);
247
+ return 1;
248
+ }
249
+
250
+ static int test3(struct io_uring *ring, int *fd)
251
+ {
252
+ struct io_uring_sqe *sqe;
253
+ struct io_uring_cqe *cqe;
254
+ int ret, i, fd2[2];
255
+
256
+ if (pipe(fd2) < 0) {
257
+ perror("pipe");
258
+ return 1;
259
+ }
260
+
261
+ for (i = 0; i < 8; i++) {
262
+ sqe = io_uring_get_sqe(ring);
263
+ if (!sqe) {
264
+ fprintf(stderr, "get sqe failed\n");
265
+ goto err;
266
+ }
267
+
268
+ if (!(i & 1)) {
269
+ io_uring_prep_poll_add(sqe, fd[0], POLLIN);
270
+ sqe->flags |= IOSQE_ASYNC;
271
+ } else
272
+ io_uring_prep_poll_add(sqe, fd2[0], POLLIN);
273
+ sqe->user_data = i & 1;
274
+ }
275
+
276
+ ret = io_uring_submit(ring);
277
+ if (ret < 8) {
278
+ fprintf(stderr, "child: sqe submit failed: %d\n", ret);
279
+ goto err;
280
+ }
281
+
282
+ usleep(10000);
283
+
284
+ sqe = io_uring_get_sqe(ring);
285
+ if (!sqe) {
286
+ fprintf(stderr, "get sqe failed\n");
287
+ goto err;
288
+ }
289
+
290
+ /*
291
+ * Mark CANCEL_ALL to cancel all matching the key, and use
292
+ * CANCEL_FD to cancel requests matching the specified fd.
293
+ * This should cancel all the pending poll requests on the pipe
294
+ * input.
295
+ */
296
+ io_uring_prep_cancel(sqe, 0, IORING_ASYNC_CANCEL_ALL);
297
+ sqe->cancel_flags |= IORING_ASYNC_CANCEL_ANY;
298
+ sqe->fd = 0;
299
+ sqe->user_data = 100;
300
+
301
+ ret = io_uring_submit(ring);
302
+ if (ret < 1) {
303
+ fprintf(stderr, "child: sqe submit failed: %d\n", ret);
304
+ goto err;
305
+ }
306
+
307
+ for (i = 0; i < 9; i++) {
308
+ ret = io_uring_wait_cqe(ring, &cqe);
309
+ if (ret) {
310
+ fprintf(stderr, "wait=%d\n", ret);
311
+ goto err;
312
+ }
313
+ switch (cqe->user_data) {
314
+ case 100:
315
+ if (cqe->res != 8) {
316
+ fprintf(stderr, "canceled %d\n", cqe->res);
317
+ goto err;
318
+ }
319
+ break;
320
+ case 0:
321
+ case 1:
322
+ if (cqe->res != -ECANCELED) {
323
+ fprintf(stderr, "poll res %d\n", cqe->res);
324
+ goto err;
325
+ }
326
+ break;
327
+ default:
328
+ fprintf(stderr, "invalid user_data %lu\n",
329
+ (unsigned long) cqe->user_data);
330
+ goto err;
331
+ }
332
+ io_uring_cqe_seen(ring, cqe);
333
+ }
334
+
335
+ close(fd2[0]);
336
+ close(fd2[1]);
337
+ return 0;
338
+ err:
339
+ close(fd2[0]);
340
+ close(fd2[1]);
341
+ return 1;
342
+ }
343
+
344
+ static int test4(struct io_uring *ring, int *fd)
345
+ {
346
+ struct io_uring_sqe *sqe;
347
+ struct io_uring_cqe *cqe;
348
+ char buffer[32];
349
+ int ret, i;
350
+
351
+ for (i = 0; i < 8; i++) {
352
+ sqe = io_uring_get_sqe(ring);
353
+ if (!sqe) {
354
+ fprintf(stderr, "get sqe failed\n");
355
+ goto err;
356
+ }
357
+
358
+ io_uring_prep_read(sqe, fd[0], &buffer, sizeof(buffer), 0);
359
+ sqe->flags |= IOSQE_ASYNC;
360
+ sqe->user_data = i + 1;
361
+ }
362
+
363
+ ret = io_uring_submit(ring);
364
+ if (ret < 8) {
365
+ fprintf(stderr, "child: sqe submit failed: %d\n", ret);
366
+ goto err;
367
+ }
368
+
369
+ usleep(10000);
370
+
371
+ sqe = io_uring_get_sqe(ring);
372
+ if (!sqe) {
373
+ fprintf(stderr, "get sqe failed\n");
374
+ goto err;
375
+ }
376
+
377
+ /*
378
+ * Mark CANCEL_ALL to cancel all matching the key, and use
379
+ * CANCEL_FD to cancel requests matching the specified fd.
380
+ * This should cancel all the pending poll requests on the pipe
381
+ * input.
382
+ */
383
+ io_uring_prep_cancel(sqe, 0, IORING_ASYNC_CANCEL_ALL);
384
+ sqe->cancel_flags |= IORING_ASYNC_CANCEL_ANY;
385
+ sqe->fd = 0;
386
+ sqe->user_data = 100;
387
+
388
+ ret = io_uring_submit(ring);
389
+ if (ret < 1) {
390
+ fprintf(stderr, "child: sqe submit failed: %d\n", ret);
391
+ goto err;
392
+ }
393
+
394
+ for (i = 0; i < 9; i++) {
395
+ ret = io_uring_wait_cqe(ring, &cqe);
396
+ if (ret) {
397
+ fprintf(stderr, "wait=%d\n", ret);
398
+ goto err;
399
+ }
400
+ switch (cqe->user_data) {
401
+ case 100:
402
+ if (cqe->res != 8) {
403
+ fprintf(stderr, "canceled %d\n", cqe->res);
404
+ goto err;
405
+ }
406
+ break;
407
+ case 1 ... 8:
408
+ if (cqe->res != -ECANCELED) {
409
+ fprintf(stderr, "poll res %d\n", cqe->res);
410
+ goto err;
411
+ }
412
+ break;
413
+ default:
414
+ fprintf(stderr, "invalid user_data %lu\n",
415
+ (unsigned long) cqe->user_data);
416
+ goto err;
417
+ }
418
+ io_uring_cqe_seen(ring, cqe);
419
+ }
420
+
421
+ return 0;
422
+ err:
423
+ return 1;
424
+ }
425
+
426
+ int main(int argc, char *argv[])
427
+ {
428
+ struct io_uring ring;
429
+ int ret, fd[2];
430
+
431
+ if (argc > 1)
432
+ return 0;
433
+
434
+ if (pipe(fd) < 0) {
435
+ perror("pipe");
436
+ return 1;
437
+ }
438
+
439
+ ret = io_uring_queue_init(8, &ring, 0);
440
+ if (ret) {
441
+ fprintf(stderr, "ring setup failed: %d\n", ret);
442
+ return 1;
443
+ }
444
+
445
+ ret = test1(&ring, fd);
446
+ if (ret) {
447
+ fprintf(stderr, "test1 failed\n");
448
+ return ret;
449
+ }
450
+ if (no_cancel_flags)
451
+ return 0;
452
+
453
+ ret = test2(&ring, fd);
454
+ if (ret) {
455
+ fprintf(stderr, "test2 failed\n");
456
+ return ret;
457
+ }
458
+
459
+ ret = test3(&ring, fd);
460
+ if (ret) {
461
+ fprintf(stderr, "test3 failed\n");
462
+ return ret;
463
+ }
464
+
465
+ ret = test4(&ring, fd);
466
+ if (ret) {
467
+ fprintf(stderr, "test4 failed\n");
468
+ return ret;
469
+ }
470
+
471
+ return 0;
472
+ }
@@ -13,6 +13,7 @@
13
13
  #include <poll.h>
14
14
  #include <arpa/inet.h>
15
15
 
16
+ #include "helpers.h"
16
17
  #include "liburing.h"
17
18
 
18
19
  pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
@@ -50,15 +51,15 @@ struct data {
50
51
 
51
52
  static void *send_thread(void *arg)
52
53
  {
54
+ struct sockaddr_in addr;
53
55
  struct data *data = arg;
56
+ int s0;
54
57
 
55
58
  wait_for_var(&recv_thread_ready);
56
59
 
57
- int s0 = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
60
+ s0 = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
58
61
  assert(s0 != -1);
59
62
 
60
- struct sockaddr_in addr;
61
-
62
63
  addr.sin_family = AF_INET;
63
64
  addr.sin_port = data->port;
64
65
  addr.sin_addr.s_addr = data->addr;
@@ -72,6 +73,7 @@ static void *send_thread(void *arg)
72
73
 
73
74
  void *recv_thread(void *arg)
74
75
  {
76
+ struct sockaddr_in addr = { };
75
77
  struct data *data = arg;
76
78
  struct io_uring_sqe *sqe;
77
79
  struct io_uring ring;
@@ -89,27 +91,17 @@ void *recv_thread(void *arg)
89
91
  ret = setsockopt(s0, SOL_SOCKET, SO_REUSEADDR, &val, sizeof(val));
90
92
  assert(ret != -1);
91
93
 
92
- struct sockaddr_in addr;
93
-
94
94
  addr.sin_family = AF_INET;
95
95
  data->addr = inet_addr("127.0.0.1");
96
96
  addr.sin_addr.s_addr = data->addr;
97
97
 
98
- i = 0;
99
- do {
100
- data->port = htons(1025 + (rand() % 64510));
101
- addr.sin_port = data->port;
102
-
103
- if (bind(s0, (struct sockaddr*)&addr, sizeof(addr)) != -1)
104
- break;
105
- } while (++i < 100);
106
-
107
- if (i >= 100) {
108
- fprintf(stderr, "Can't find good port, skipped\n");
98
+ if (t_bind_ephemeral_port(s0, &addr)) {
99
+ perror("bind");
109
100
  data->stop = 1;
110
101
  signal_var(&recv_thread_ready);
111
- goto out;
102
+ goto err;
112
103
  }
104
+ data->port = addr.sin_port;
113
105
 
114
106
  ret = listen(s0, 128);
115
107
  assert(ret != -1);
@@ -158,7 +150,6 @@ void *recv_thread(void *arg)
158
150
  io_uring_cqe_seen(&ring, cqe);
159
151
  }
160
152
 
161
- out:
162
153
  signal_var(&recv_thread_done);
163
154
  close(s0);
164
155
  io_uring_queue_exit(&ring);
@@ -0,0 +1,162 @@
1
+ // SPDX-License-Identifier: MIT
2
+
3
+ #include <errno.h>
4
+ #include <stdio.h>
5
+ #include <unistd.h>
6
+ #include <stdlib.h>
7
+ #include <string.h>
8
+ #include <signal.h>
9
+ #include <poll.h>
10
+ #include <sys/wait.h>
11
+
12
+ #include "liburing.h"
13
+ #include "helpers.h"
14
+
15
+ int check_final_cqe(struct io_uring *ring)
16
+ {
17
+ struct io_uring_cqe *cqe;
18
+ int count = 0;
19
+ bool signalled_no_more = false;
20
+
21
+ while (!io_uring_peek_cqe(ring, &cqe)) {
22
+ if (cqe->user_data == 1) {
23
+ count++;
24
+ if (signalled_no_more) {
25
+ fprintf(stderr, "signalled no more!\n");
26
+ return T_EXIT_FAIL;
27
+ }
28
+ if (!(cqe->flags & IORING_CQE_F_MORE))
29
+ signalled_no_more = true;
30
+ } else if (cqe->user_data != 3) {
31
+ fprintf(stderr, "%d: got unexpected %d\n", count, (int)cqe->user_data);
32
+ return T_EXIT_FAIL;
33
+ }
34
+ io_uring_cqe_seen(ring, cqe);
35
+ }
36
+
37
+ if (!count) {
38
+ fprintf(stderr, "no cqe\n");
39
+ return T_EXIT_FAIL;
40
+ }
41
+
42
+ return T_EXIT_PASS;
43
+ }
44
+
45
+ static int test(bool defer_taskrun)
46
+ {
47
+ struct io_uring_cqe *cqe;
48
+ struct io_uring_sqe *sqe;
49
+ struct io_uring ring;
50
+ int pipe1[2];
51
+ int ret, i;
52
+
53
+ if (pipe(pipe1) != 0) {
54
+ perror("pipe");
55
+ return T_EXIT_FAIL;
56
+ }
57
+
58
+ struct io_uring_params params = {
59
+ /* cheat using SINGLE_ISSUER existence to know if this behaviour
60
+ * is updated
61
+ */
62
+ .flags = IORING_SETUP_CQSIZE | IORING_SETUP_SINGLE_ISSUER,
63
+ .cq_entries = 2
64
+ };
65
+
66
+ if (defer_taskrun)
67
+ params.flags |= IORING_SETUP_SINGLE_ISSUER |
68
+ IORING_SETUP_DEFER_TASKRUN;
69
+
70
+ ret = io_uring_queue_init_params(2, &ring, &params);
71
+ if (ret)
72
+ return T_EXIT_SKIP;
73
+
74
+ sqe = io_uring_get_sqe(&ring);
75
+ if (!sqe) {
76
+ fprintf(stderr, "get sqe failed\n");
77
+ return T_EXIT_FAIL;
78
+ }
79
+ io_uring_prep_poll_multishot(sqe, pipe1[0], POLLIN);
80
+ io_uring_sqe_set_data64(sqe, 1);
81
+
82
+ if (io_uring_cq_ready(&ring)) {
83
+ fprintf(stderr, "unexpected cqe\n");
84
+ return T_EXIT_FAIL;
85
+ }
86
+
87
+ for (i = 0; i < 2; i++) {
88
+ sqe = io_uring_get_sqe(&ring);
89
+ io_uring_prep_nop(sqe);
90
+ io_uring_sqe_set_data64(sqe, 2);
91
+ io_uring_submit(&ring);
92
+ }
93
+
94
+ do {
95
+ errno = 0;
96
+ ret = write(pipe1[1], "foo", 3);
97
+ } while (ret == -1 && errno == EINTR);
98
+
99
+ if (ret <= 0) {
100
+ fprintf(stderr, "write failed: %d\n", errno);
101
+ return T_EXIT_FAIL;
102
+ }
103
+
104
+ /* should have 2 cqe + 1 overflow now, so take out two cqes */
105
+ for (i = 0; i < 2; i++) {
106
+ if (io_uring_peek_cqe(&ring, &cqe)) {
107
+ fprintf(stderr, "unexpectedly no cqe\n");
108
+ return T_EXIT_FAIL;
109
+ }
110
+ if (cqe->user_data != 2) {
111
+ fprintf(stderr, "unexpected user_data\n");
112
+ return T_EXIT_FAIL;
113
+ }
114
+ io_uring_cqe_seen(&ring, cqe);
115
+ }
116
+
117
+ /* make sure everything is processed */
118
+ io_uring_get_events(&ring);
119
+
120
+ /* now remove the poll */
121
+ sqe = io_uring_get_sqe(&ring);
122
+ io_uring_prep_poll_remove(sqe, 1);
123
+ io_uring_sqe_set_data64(sqe, 3);
124
+ ret = io_uring_submit(&ring);
125
+
126
+ if (ret != 1) {
127
+ fprintf(stderr, "bad poll remove\n");
128
+ return T_EXIT_FAIL;
129
+ }
130
+
131
+ ret = check_final_cqe(&ring);
132
+
133
+ close(pipe1[0]);
134
+ close(pipe1[1]);
135
+ io_uring_queue_exit(&ring);
136
+
137
+ return ret;
138
+ }
139
+
140
+ int main(int argc, char *argv[])
141
+ {
142
+ int ret;
143
+
144
+ if (argc > 1)
145
+ return T_EXIT_SKIP;
146
+
147
+ ret = test(false);
148
+ if (ret != T_EXIT_PASS) {
149
+ fprintf(stderr, "%s: test(false) failed\n", argv[0]);
150
+ return ret;
151
+ }
152
+
153
+ if (t_probe_defer_taskrun()) {
154
+ ret = test(true);
155
+ if (ret != T_EXIT_PASS) {
156
+ fprintf(stderr, "%s: test(true) failed\n", argv[0]);
157
+ return ret;
158
+ }
159
+ }
160
+
161
+ return ret;
162
+ }