uringmachine 0.3 → 0.5

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 (167) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/test.yml +2 -1
  3. data/CHANGELOG.md +23 -0
  4. data/README.md +128 -0
  5. data/TODO.md +14 -0
  6. data/examples/bm_snooze.rb +89 -0
  7. data/examples/bm_write.rb +56 -0
  8. data/examples/dns_client.rb +12 -0
  9. data/examples/echo_server.rb +18 -40
  10. data/examples/http_server.rb +42 -43
  11. data/examples/inout.rb +19 -0
  12. data/examples/nc.rb +36 -0
  13. data/examples/server_client.rb +64 -0
  14. data/examples/snooze.rb +44 -0
  15. data/examples/write_dev_null.rb +16 -0
  16. data/ext/um/extconf.rb +24 -23
  17. data/ext/um/um.c +524 -278
  18. data/ext/um/um.h +146 -44
  19. data/ext/um/um_buffer.c +49 -0
  20. data/ext/um/um_class.c +217 -106
  21. data/ext/um/um_const.c +213 -0
  22. data/ext/um/um_ext.c +4 -0
  23. data/ext/um/um_mutex_class.c +47 -0
  24. data/ext/um/um_op.c +86 -114
  25. data/ext/um/um_queue_class.c +58 -0
  26. data/ext/um/um_sync.c +273 -0
  27. data/ext/um/um_utils.c +49 -4
  28. data/lib/uringmachine/dns_resolver.rb +84 -0
  29. data/lib/uringmachine/version.rb +1 -1
  30. data/lib/uringmachine.rb +28 -0
  31. data/supressions/ruby.supp +71 -0
  32. data/test/helper.rb +8 -0
  33. data/test/test_um.rb +685 -46
  34. data/vendor/liburing/.github/workflows/build.yml +29 -1
  35. data/vendor/liburing/.gitignore +6 -0
  36. data/vendor/liburing/CHANGELOG +16 -0
  37. data/vendor/liburing/CONTRIBUTING.md +165 -0
  38. data/vendor/liburing/configure +64 -0
  39. data/vendor/liburing/examples/Makefile +9 -1
  40. data/vendor/liburing/examples/kdigest.c +405 -0
  41. data/vendor/liburing/examples/proxy.c +75 -8
  42. data/vendor/liburing/examples/reg-wait.c +159 -0
  43. data/vendor/liburing/liburing.pc.in +1 -1
  44. data/vendor/liburing/liburing.spec +1 -1
  45. data/vendor/liburing/src/Makefile +16 -2
  46. data/vendor/liburing/src/include/liburing/io_uring.h +77 -0
  47. data/vendor/liburing/src/include/liburing/sanitize.h +39 -0
  48. data/vendor/liburing/src/include/liburing.h +59 -6
  49. data/vendor/liburing/src/int_flags.h +10 -3
  50. data/vendor/liburing/src/liburing-ffi.map +16 -0
  51. data/vendor/liburing/src/liburing.map +10 -0
  52. data/vendor/liburing/src/queue.c +28 -16
  53. data/vendor/liburing/src/register.c +106 -1
  54. data/vendor/liburing/src/sanitize.c +176 -0
  55. data/vendor/liburing/src/setup.c +47 -19
  56. data/vendor/liburing/src/setup.h +6 -0
  57. data/vendor/liburing/test/35fa71a030ca.c +7 -0
  58. data/vendor/liburing/test/500f9fbadef8.c +2 -0
  59. data/vendor/liburing/test/7ad0e4b2f83c.c +0 -25
  60. data/vendor/liburing/test/917257daa0fe.c +7 -0
  61. data/vendor/liburing/test/Makefile +38 -4
  62. data/vendor/liburing/test/a0908ae19763.c +7 -0
  63. data/vendor/liburing/test/a4c0b3decb33.c +7 -0
  64. data/vendor/liburing/test/accept.c +14 -4
  65. data/vendor/liburing/test/b19062a56726.c +7 -0
  66. data/vendor/liburing/test/bind-listen.c +2 -2
  67. data/vendor/liburing/test/buf-ring-nommap.c +10 -3
  68. data/vendor/liburing/test/buf-ring.c +2 -0
  69. data/vendor/liburing/test/cmd-discard.c +427 -0
  70. data/vendor/liburing/test/coredump.c +7 -0
  71. data/vendor/liburing/test/cq-overflow.c +13 -1
  72. data/vendor/liburing/test/d4ae271dfaae.c +11 -3
  73. data/vendor/liburing/test/defer-taskrun.c +2 -2
  74. data/vendor/liburing/test/defer-tw-timeout.c +4 -1
  75. data/vendor/liburing/test/defer.c +2 -2
  76. data/vendor/liburing/test/double-poll-crash.c +1 -1
  77. data/vendor/liburing/test/eeed8b54e0df.c +2 -0
  78. data/vendor/liburing/test/eventfd.c +0 -1
  79. data/vendor/liburing/test/exit-no-cleanup.c +11 -0
  80. data/vendor/liburing/test/fadvise.c +9 -26
  81. data/vendor/liburing/test/fdinfo.c +9 -1
  82. data/vendor/liburing/test/fifo-nonblock-read.c +69 -0
  83. data/vendor/liburing/test/file-exit-unreg.c +48 -0
  84. data/vendor/liburing/test/file-register.c +14 -2
  85. data/vendor/liburing/test/file-update.c +1 -1
  86. data/vendor/liburing/test/file-verify.c +27 -16
  87. data/vendor/liburing/test/files-exit-hang-timeout.c +1 -2
  88. data/vendor/liburing/test/fixed-buf-iter.c +3 -1
  89. data/vendor/liburing/test/fixed-hugepage.c +12 -1
  90. data/vendor/liburing/test/fsnotify.c +1 -0
  91. data/vendor/liburing/test/futex.c +16 -4
  92. data/vendor/liburing/test/helpers.c +47 -0
  93. data/vendor/liburing/test/helpers.h +6 -0
  94. data/vendor/liburing/test/init-mem.c +5 -3
  95. data/vendor/liburing/test/io-cancel.c +0 -24
  96. data/vendor/liburing/test/io_uring_passthrough.c +4 -0
  97. data/vendor/liburing/test/io_uring_register.c +38 -8
  98. data/vendor/liburing/test/iopoll-leak.c +4 -0
  99. data/vendor/liburing/test/iopoll-overflow.c +1 -1
  100. data/vendor/liburing/test/iopoll.c +3 -3
  101. data/vendor/liburing/test/kallsyms.c +203 -0
  102. data/vendor/liburing/test/link-timeout.c +159 -0
  103. data/vendor/liburing/test/linked-defer-close.c +224 -0
  104. data/vendor/liburing/test/madvise.c +12 -25
  105. data/vendor/liburing/test/min-timeout-wait.c +0 -25
  106. data/vendor/liburing/test/min-timeout.c +0 -25
  107. data/vendor/liburing/test/mkdir.c +6 -0
  108. data/vendor/liburing/test/msg-ring.c +8 -2
  109. data/vendor/liburing/test/napi-test.c +16 -3
  110. data/vendor/liburing/test/no-mmap-inval.c +3 -1
  111. data/vendor/liburing/test/nop.c +44 -0
  112. data/vendor/liburing/test/ooo-file-unreg.c +1 -1
  113. data/vendor/liburing/test/open-close.c +40 -0
  114. data/vendor/liburing/test/openat2.c +37 -14
  115. data/vendor/liburing/test/poll-many.c +13 -7
  116. data/vendor/liburing/test/poll-mshot-update.c +17 -10
  117. data/vendor/liburing/test/poll-v-poll.c +6 -3
  118. data/vendor/liburing/test/pollfree.c +148 -0
  119. data/vendor/liburing/test/read-mshot-empty.c +158 -153
  120. data/vendor/liburing/test/read-mshot-stdin.c +121 -0
  121. data/vendor/liburing/test/read-mshot.c +282 -27
  122. data/vendor/liburing/test/read-write.c +78 -13
  123. data/vendor/liburing/test/recv-msgall-stream.c +3 -0
  124. data/vendor/liburing/test/recv-msgall.c +5 -0
  125. data/vendor/liburing/test/recvsend_bundle-inc.c +680 -0
  126. data/vendor/liburing/test/recvsend_bundle.c +94 -31
  127. data/vendor/liburing/test/reg-fd-only.c +15 -5
  128. data/vendor/liburing/test/reg-wait.c +251 -0
  129. data/vendor/liburing/test/regbuf-clone.c +645 -0
  130. data/vendor/liburing/test/regbuf-merge.c +7 -0
  131. data/vendor/liburing/test/register-restrictions.c +86 -85
  132. data/vendor/liburing/test/rename.c +59 -1
  133. data/vendor/liburing/test/resize-rings.c +643 -0
  134. data/vendor/liburing/test/ringbuf-read.c +5 -0
  135. data/vendor/liburing/test/ringbuf-status.c +5 -1
  136. data/vendor/liburing/test/rsrc_tags.c +1 -1
  137. data/vendor/liburing/test/runtests.sh +16 -1
  138. data/vendor/liburing/test/send-zerocopy.c +59 -0
  139. data/vendor/liburing/test/short-read.c +1 -0
  140. data/vendor/liburing/test/socket.c +43 -0
  141. data/vendor/liburing/test/splice.c +3 -1
  142. data/vendor/liburing/test/sq-poll-dup.c +1 -1
  143. data/vendor/liburing/test/sq-poll-share.c +2 -0
  144. data/vendor/liburing/test/sqpoll-disable-exit.c +8 -0
  145. data/vendor/liburing/test/sqpoll-exit-hang.c +1 -25
  146. data/vendor/liburing/test/sqpoll-sleep.c +40 -33
  147. data/vendor/liburing/test/sqwait.c +136 -0
  148. data/vendor/liburing/test/statx.c +89 -0
  149. data/vendor/liburing/test/stdout.c +2 -0
  150. data/vendor/liburing/test/submit-and-wait.c +1 -25
  151. data/vendor/liburing/test/submit-reuse.c +4 -26
  152. data/vendor/liburing/test/symlink.c +12 -1
  153. data/vendor/liburing/test/sync-cancel.c +56 -22
  154. data/vendor/liburing/test/thread-exit.c +5 -0
  155. data/vendor/liburing/test/timeout-new.c +1 -26
  156. data/vendor/liburing/test/timeout.c +25 -34
  157. data/vendor/liburing/test/unlink.c +94 -1
  158. data/vendor/liburing/test/uring_cmd_ublk.c +1252 -0
  159. data/vendor/liburing/test/waitid.c +62 -8
  160. data/vendor/liburing/test/wq-aff.c +35 -0
  161. data/vendor/liburing/test/xfail_prep_link_timeout_out_of_scope.c +46 -0
  162. data/vendor/liburing/test/xfail_register_buffers_out_of_scope.c +51 -0
  163. metadata +37 -6
  164. data/examples/event_loop.rb +0 -69
  165. data/examples/fibers.rb +0 -105
  166. data/examples/http_server_multishot.rb +0 -57
  167. data/examples/http_server_simpler.rb +0 -34
@@ -19,6 +19,39 @@ static void child(long usleep_time)
19
19
  exit(0);
20
20
  }
21
21
 
22
+ static int test_invalid_infop(struct io_uring *ring)
23
+ {
24
+ struct io_uring_sqe *sqe;
25
+ struct io_uring_cqe *cqe;
26
+ siginfo_t *si = (siginfo_t *) (uintptr_t) 0x1234;
27
+ int ret, w;
28
+ pid_t pid;
29
+
30
+ pid = fork();
31
+ if (!pid) {
32
+ child(200000);
33
+ exit(0);
34
+ }
35
+
36
+ sqe = io_uring_get_sqe(ring);
37
+ io_uring_prep_waitid(sqe, P_PID, pid, si, WEXITED, 0);
38
+ sqe->user_data = 1;
39
+ io_uring_submit(ring);
40
+
41
+ ret = io_uring_wait_cqe(ring, &cqe);
42
+ if (ret) {
43
+ fprintf(stderr, "cqe wait: %d\n", ret);
44
+ return T_EXIT_FAIL;
45
+ }
46
+ if (cqe->res != -EFAULT) {
47
+ fprintf(stderr, "Bad return on invalid infop: %d\n", cqe->res);
48
+ return T_EXIT_FAIL;
49
+ }
50
+ io_uring_cqe_seen(ring, cqe);
51
+ wait(&w);
52
+ return T_EXIT_PASS;
53
+ }
54
+
22
55
  /*
23
56
  * Test linked timeout with child not exiting in time
24
57
  */
@@ -27,9 +60,9 @@ static int test_noexit(struct io_uring *ring)
27
60
  struct io_uring_sqe *sqe;
28
61
  struct io_uring_cqe *cqe;
29
62
  struct __kernel_timespec ts;
63
+ int ret, i, w;
30
64
  siginfo_t si;
31
65
  pid_t pid;
32
- int ret, i;
33
66
 
34
67
  pid = fork();
35
68
  if (!pid) {
@@ -67,6 +100,7 @@ static int test_noexit(struct io_uring *ring)
67
100
  io_uring_cqe_seen(ring, cqe);
68
101
  }
69
102
 
103
+ wait(&w);
70
104
  return T_EXIT_PASS;
71
105
  }
72
106
 
@@ -79,7 +113,7 @@ static int test_double(struct io_uring *ring)
79
113
  struct io_uring_cqe *cqe;
80
114
  siginfo_t si;
81
115
  pid_t p1, p2;
82
- int ret;
116
+ int ret, w;
83
117
 
84
118
  /* p1 will exit shortly */
85
119
  p1 = fork();
@@ -116,6 +150,7 @@ static int test_double(struct io_uring *ring)
116
150
  }
117
151
 
118
152
  io_uring_cqe_seen(ring, cqe);
153
+ wait(&w);
119
154
  return T_EXIT_PASS;
120
155
  }
121
156
 
@@ -167,7 +202,7 @@ static int test_cancel(struct io_uring *ring)
167
202
  {
168
203
  struct io_uring_sqe *sqe;
169
204
  struct io_uring_cqe *cqe;
170
- int ret, i;
205
+ int ret, i, w;
171
206
  pid_t pid;
172
207
 
173
208
  pid = fork();
@@ -205,6 +240,7 @@ static int test_cancel(struct io_uring *ring)
205
240
  io_uring_cqe_seen(ring, cqe);
206
241
  }
207
242
 
243
+ wait(&w);
208
244
  return T_EXIT_PASS;
209
245
  }
210
246
 
@@ -216,10 +252,12 @@ static int test_cancel_race(struct io_uring *ring, int async)
216
252
  {
217
253
  struct io_uring_sqe *sqe;
218
254
  struct io_uring_cqe *cqe;
219
- int ret, i;
255
+ int ret, i, to_wait, total_forks;
220
256
  pid_t pid;
221
257
 
258
+ total_forks = 0;
222
259
  for (i = 0; i < 10; i++) {
260
+ total_forks++;
223
261
  pid = fork();
224
262
  if (!pid) {
225
263
  child(getpid() & 1);
@@ -243,16 +281,20 @@ static int test_cancel_race(struct io_uring *ring, int async)
243
281
 
244
282
  io_uring_submit(ring);
245
283
 
284
+ to_wait = total_forks;
246
285
  for (i = 0; i < 2; i++) {
247
286
  ret = io_uring_wait_cqe(ring, &cqe);
248
287
  if (ret) {
249
288
  fprintf(stderr, "cqe wait: %d\n", ret);
250
289
  return T_EXIT_FAIL;
251
290
  }
252
- if (cqe->user_data == 1 && !(cqe->res == -ECANCELED ||
253
- cqe->res == 0)) {
254
- fprintf(stderr, "cqe1 res: %d\n", cqe->res);
255
- return T_EXIT_FAIL;
291
+ if (cqe->user_data == 1) {
292
+ if (!cqe->res)
293
+ to_wait--;
294
+ if (!(cqe->res == -ECANCELED || cqe->res == 0)) {
295
+ fprintf(stderr, "cqe1 res: %d\n", cqe->res);
296
+ return T_EXIT_FAIL;
297
+ }
256
298
  }
257
299
  if (cqe->user_data == 2 &&
258
300
  !(cqe->res == 1 || cqe->res == 0 || cqe->res == -ENOENT ||
@@ -263,6 +305,12 @@ static int test_cancel_race(struct io_uring *ring, int async)
263
305
  io_uring_cqe_seen(ring, cqe);
264
306
  }
265
307
 
308
+ for (i = 0; i < to_wait; i++) {
309
+ int w;
310
+
311
+ wait(&w);
312
+ }
313
+
266
314
  return T_EXIT_PASS;
267
315
  }
268
316
 
@@ -360,6 +408,12 @@ int main(int argc, char *argv[])
360
408
  return T_EXIT_FAIL;
361
409
  }
362
410
 
411
+ ret = test_invalid_infop(&ring);
412
+ if (ret == T_EXIT_FAIL) {
413
+ fprintf(stderr, "test_invalid_infop failed\n");
414
+ return T_EXIT_FAIL;
415
+ }
416
+
363
417
  for (i = 0; i < 1000; i++) {
364
418
  ret = test_cancel_race(&ring, i & 1);
365
419
  if (ret == T_EXIT_FAIL) {
@@ -127,6 +127,33 @@ static int test(int sqpoll)
127
127
  return ret;
128
128
  }
129
129
 
130
+ static int test_invalid_cpu(void)
131
+ {
132
+ struct io_uring_params p = { };
133
+ struct io_uring ring;
134
+ int ret, nr_cpus;
135
+
136
+ nr_cpus = sysconf(_SC_NPROCESSORS_ONLN);
137
+ if (nr_cpus < 0) {
138
+ perror("sysconf(_SC_NPROCESSORS_ONLN");
139
+ return T_EXIT_SKIP;
140
+ }
141
+
142
+ p.flags = IORING_SETUP_SQPOLL | IORING_SETUP_SQ_AFF;
143
+ p.sq_thread_cpu = 16 * nr_cpus;
144
+
145
+ ret = io_uring_queue_init_params(8, &ring, &p);
146
+ if (ret == -EPERM) {
147
+ return T_EXIT_SKIP;
148
+ } else if (ret != -EINVAL) {
149
+ fprintf(stderr, "Queue init: %d\n", ret);
150
+ return T_EXIT_FAIL;
151
+ }
152
+
153
+ io_uring_queue_exit(&ring);
154
+ return T_EXIT_PASS;
155
+ }
156
+
130
157
  int main(int argc, char *argv[])
131
158
  {
132
159
  int ret;
@@ -134,6 +161,14 @@ int main(int argc, char *argv[])
134
161
  if (argc > 1)
135
162
  return T_EXIT_SKIP;
136
163
 
164
+ ret = test_invalid_cpu();
165
+ if (ret == T_EXIT_SKIP) {
166
+ return T_EXIT_SKIP;
167
+ } else if (ret != T_EXIT_PASS) {
168
+ fprintf(stderr, "test sqpoll cpu failed\n");
169
+ return T_EXIT_FAIL;
170
+ }
171
+
137
172
  ret = test(1);
138
173
  if (ret == T_EXIT_SKIP) {
139
174
  return T_EXIT_SKIP;
@@ -0,0 +1,46 @@
1
+ /* SPDX-License-Identifier: MIT */
2
+ /*
3
+ * Description: Check to see if the asan checks catch an stack-use-after-free for prep_link_timeout
4
+ */
5
+
6
+ #include <stdio.h>
7
+ #include <errno.h>
8
+ #include <sys/socket.h>
9
+ #include <sys/un.h>
10
+ #include <assert.h>
11
+ #include "liburing.h"
12
+ #include "helpers.h"
13
+
14
+ #include <stdio.h>
15
+
16
+ int main(int argc, char *argv[])
17
+ {
18
+ struct io_uring ring;
19
+ struct io_uring_sqe *sqe;
20
+ int ret;
21
+
22
+ if (argc > 1)
23
+ return T_EXIT_SKIP;
24
+
25
+ ret = io_uring_queue_init(8, &ring, 0);
26
+ if (ret < 0) {
27
+ printf("io_uring_queue_init ret %i\n", ret);
28
+ return T_EXIT_PASS; // this test expects an inverted exit code
29
+ }
30
+
31
+ // force timespec to go out of scope, test "passes" if asan catches this bug.
32
+ {
33
+ struct __kernel_timespec timespec;
34
+ timespec.tv_sec = 0;
35
+ timespec.tv_nsec = 5000;
36
+
37
+ sqe = io_uring_get_sqe(&ring);
38
+ io_uring_prep_timeout(sqe, &timespec, 0, 0);
39
+ io_uring_sqe_set_data(sqe, (void *) 1);
40
+ }
41
+
42
+ ret = io_uring_submit_and_wait(&ring, 1);
43
+ printf("submit_and_wait %i\n", ret);
44
+
45
+ return T_EXIT_PASS; // this test expects an inverted exit code
46
+ }
@@ -0,0 +1,51 @@
1
+ /* SPDX-License-Identifier: MIT */
2
+ /*
3
+ * Description: Check to see if the asan checks catch an stack-use-after-free for io_uring_sqe_set_data
4
+ */
5
+
6
+ #include <stdio.h>
7
+ #include <errno.h>
8
+ #include <sys/socket.h>
9
+ #include <sys/un.h>
10
+ #include <assert.h>
11
+ #include <stdlib.h>
12
+ #include "liburing.h"
13
+ #include "helpers.h"
14
+
15
+ #include <stdio.h>
16
+
17
+ #define BUFFERS 8
18
+ #define BUFFER_SIZE 128
19
+
20
+ int main(int argc, char *argv[])
21
+ {
22
+ struct io_uring ring;
23
+ struct iovec *iovs;
24
+ int i;
25
+ int ret;
26
+
27
+ if (argc > 1)
28
+ return T_EXIT_SKIP;
29
+
30
+ ret = io_uring_queue_init(8, &ring, 0);
31
+ if (ret < 0) {
32
+ printf("io_uring_queue_init ret %i\n", ret);
33
+ return T_EXIT_PASS; // this test expects an inverted exit code
34
+ }
35
+
36
+ iovs = calloc(BUFFERS, sizeof(struct iovec));
37
+ for (i = 0; i < BUFFERS; i++) {
38
+ iovs[i].iov_base = malloc(BUFFER_SIZE);
39
+ iovs[i].iov_len = BUFFER_SIZE;
40
+ }
41
+ // force one iov_base to be freed, test "passes" if asan catches this bug.
42
+ free(iovs[4].iov_base);
43
+
44
+ ret = io_uring_register_buffers(&ring, iovs, BUFFERS);
45
+ printf("io_uring_register_buffers %i\n", ret);
46
+
47
+ ret = io_uring_submit_and_wait(&ring, 1);
48
+ printf("submit_and_wait %i\n", ret);
49
+
50
+ return T_EXIT_PASS; // this test expects an inverted exit code
51
+ }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: uringmachine
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.3'
4
+ version: '0.5'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sharon Rosner
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-10-04 00:00:00.000000000 Z
11
+ date: 2024-11-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake-compiler
@@ -84,21 +84,32 @@ files:
84
84
  - README.md
85
85
  - Rakefile
86
86
  - TODO.md
87
+ - examples/bm_snooze.rb
88
+ - examples/bm_write.rb
89
+ - examples/dns_client.rb
87
90
  - examples/echo_server.rb
88
- - examples/event_loop.rb
89
- - examples/fibers.rb
90
91
  - examples/http_server.rb
91
- - examples/http_server_multishot.rb
92
- - examples/http_server_simpler.rb
92
+ - examples/inout.rb
93
+ - examples/nc.rb
94
+ - examples/server_client.rb
95
+ - examples/snooze.rb
96
+ - examples/write_dev_null.rb
93
97
  - ext/um/extconf.rb
94
98
  - ext/um/um.c
95
99
  - ext/um/um.h
100
+ - ext/um/um_buffer.c
96
101
  - ext/um/um_class.c
102
+ - ext/um/um_const.c
97
103
  - ext/um/um_ext.c
104
+ - ext/um/um_mutex_class.c
98
105
  - ext/um/um_op.c
106
+ - ext/um/um_queue_class.c
107
+ - ext/um/um_sync.c
99
108
  - ext/um/um_utils.c
100
109
  - lib/uringmachine.rb
110
+ - lib/uringmachine/dns_resolver.rb
101
111
  - lib/uringmachine/version.rb
112
+ - supressions/ruby.supp
102
113
  - test/helper.rb
103
114
  - test/test_um.rb
104
115
  - uringmachine.gemspec
@@ -110,6 +121,7 @@ files:
110
121
  - vendor/liburing/.gitignore
111
122
  - vendor/liburing/CHANGELOG
112
123
  - vendor/liburing/CITATION.cff
124
+ - vendor/liburing/CONTRIBUTING.md
113
125
  - vendor/liburing/COPYING
114
126
  - vendor/liburing/COPYING.GPL
115
127
  - vendor/liburing/LICENSE
@@ -140,12 +152,14 @@ files:
140
152
  - vendor/liburing/examples/io_uring-cp.c
141
153
  - vendor/liburing/examples/io_uring-test.c
142
154
  - vendor/liburing/examples/io_uring-udp.c
155
+ - vendor/liburing/examples/kdigest.c
143
156
  - vendor/liburing/examples/link-cp.c
144
157
  - vendor/liburing/examples/napi-busy-poll-client.c
145
158
  - vendor/liburing/examples/napi-busy-poll-server.c
146
159
  - vendor/liburing/examples/poll-bench.c
147
160
  - vendor/liburing/examples/proxy.c
148
161
  - vendor/liburing/examples/proxy.h
162
+ - vendor/liburing/examples/reg-wait.c
149
163
  - vendor/liburing/examples/rsrc-update-bench.c
150
164
  - vendor/liburing/examples/send-zerocopy.c
151
165
  - vendor/liburing/examples/ucontext-cp.c
@@ -167,6 +181,7 @@ files:
167
181
  - vendor/liburing/src/include/liburing.h
168
182
  - vendor/liburing/src/include/liburing/barrier.h
169
183
  - vendor/liburing/src/include/liburing/io_uring.h
184
+ - vendor/liburing/src/include/liburing/sanitize.h
170
185
  - vendor/liburing/src/int_flags.h
171
186
  - vendor/liburing/src/lib.h
172
187
  - vendor/liburing/src/liburing-ffi.map
@@ -174,6 +189,7 @@ files:
174
189
  - vendor/liburing/src/nolibc.c
175
190
  - vendor/liburing/src/queue.c
176
191
  - vendor/liburing/src/register.c
192
+ - vendor/liburing/src/sanitize.c
177
193
  - vendor/liburing/src/setup.c
178
194
  - vendor/liburing/src/setup.h
179
195
  - vendor/liburing/src/syscall.c
@@ -202,6 +218,7 @@ files:
202
218
  - vendor/liburing/test/buf-ring.c
203
219
  - vendor/liburing/test/ce593a6c480a.c
204
220
  - vendor/liburing/test/close-opath.c
221
+ - vendor/liburing/test/cmd-discard.c
205
222
  - vendor/liburing/test/config
206
223
  - vendor/liburing/test/connect-rep.c
207
224
  - vendor/liburing/test/connect.c
@@ -234,6 +251,8 @@ files:
234
251
  - vendor/liburing/test/fd-install.c
235
252
  - vendor/liburing/test/fd-pass.c
236
253
  - vendor/liburing/test/fdinfo.c
254
+ - vendor/liburing/test/fifo-nonblock-read.c
255
+ - vendor/liburing/test/file-exit-unreg.c
237
256
  - vendor/liburing/test/file-register.c
238
257
  - vendor/liburing/test/file-update.c
239
258
  - vendor/liburing/test/file-verify.c
@@ -261,11 +280,13 @@ files:
261
280
  - vendor/liburing/test/iopoll-leak.c
262
281
  - vendor/liburing/test/iopoll-overflow.c
263
282
  - vendor/liburing/test/iopoll.c
283
+ - vendor/liburing/test/kallsyms.c
264
284
  - vendor/liburing/test/lfs-openat-write.c
265
285
  - vendor/liburing/test/lfs-openat.c
266
286
  - vendor/liburing/test/link-timeout.c
267
287
  - vendor/liburing/test/link.c
268
288
  - vendor/liburing/test/link_drain.c
289
+ - vendor/liburing/test/linked-defer-close.c
269
290
  - vendor/liburing/test/madvise.c
270
291
  - vendor/liburing/test/min-timeout-wait.c
271
292
  - vendor/liburing/test/min-timeout.c
@@ -303,21 +324,27 @@ files:
303
324
  - vendor/liburing/test/poll-ring.c
304
325
  - vendor/liburing/test/poll-v-poll.c
305
326
  - vendor/liburing/test/poll.c
327
+ - vendor/liburing/test/pollfree.c
306
328
  - vendor/liburing/test/probe.c
307
329
  - vendor/liburing/test/read-before-exit.c
308
330
  - vendor/liburing/test/read-mshot-empty.c
331
+ - vendor/liburing/test/read-mshot-stdin.c
309
332
  - vendor/liburing/test/read-mshot.c
310
333
  - vendor/liburing/test/read-write.c
311
334
  - vendor/liburing/test/recv-msgall-stream.c
312
335
  - vendor/liburing/test/recv-msgall.c
313
336
  - vendor/liburing/test/recv-multishot.c
337
+ - vendor/liburing/test/recvsend_bundle-inc.c
314
338
  - vendor/liburing/test/recvsend_bundle.c
315
339
  - vendor/liburing/test/reg-fd-only.c
316
340
  - vendor/liburing/test/reg-hint.c
317
341
  - vendor/liburing/test/reg-reg-ring.c
342
+ - vendor/liburing/test/reg-wait.c
343
+ - vendor/liburing/test/regbuf-clone.c
318
344
  - vendor/liburing/test/regbuf-merge.c
319
345
  - vendor/liburing/test/register-restrictions.c
320
346
  - vendor/liburing/test/rename.c
347
+ - vendor/liburing/test/resize-rings.c
321
348
  - vendor/liburing/test/ring-leak.c
322
349
  - vendor/liburing/test/ring-leak2.c
323
350
  - vendor/liburing/test/ringbuf-read.c
@@ -354,6 +381,7 @@ files:
354
381
  - vendor/liburing/test/sqpoll-exec.c
355
382
  - vendor/liburing/test/sqpoll-exit-hang.c
356
383
  - vendor/liburing/test/sqpoll-sleep.c
384
+ - vendor/liburing/test/sqwait.c
357
385
  - vendor/liburing/test/statx.c
358
386
  - vendor/liburing/test/stdout.c
359
387
  - vendor/liburing/test/submit-and-wait.c
@@ -369,12 +397,15 @@ files:
369
397
  - vendor/liburing/test/truncate.c
370
398
  - vendor/liburing/test/tty-write-dpoll.c
371
399
  - vendor/liburing/test/unlink.c
400
+ - vendor/liburing/test/uring_cmd_ublk.c
372
401
  - vendor/liburing/test/version.c
373
402
  - vendor/liburing/test/wait-timeout.c
374
403
  - vendor/liburing/test/waitid.c
375
404
  - vendor/liburing/test/wakeup-hang.c
376
405
  - vendor/liburing/test/wq-aff.c
377
406
  - vendor/liburing/test/xattr.c
407
+ - vendor/liburing/test/xfail_prep_link_timeout_out_of_scope.c
408
+ - vendor/liburing/test/xfail_register_buffers_out_of_scope.c
378
409
  homepage: https://github.com/digital-fabric/uringmachine
379
410
  licenses:
380
411
  - MIT
@@ -1,69 +0,0 @@
1
- require_relative '../lib/iou'
2
- require 'socket'
3
-
4
- class IOUEventLoop
5
- attr_reader :ring
6
-
7
- def initialize
8
- @ring = IOU::Ring.new
9
- end
10
-
11
- def async_queue
12
- @async_queue ||= []
13
- end
14
-
15
- def async(&block)
16
- @async_queue << block
17
- signal if @waiting
18
- end
19
-
20
- def signal
21
- # generate an event to cause process_completions to return
22
- ring.prep_nop
23
- ring.submit
24
- end
25
-
26
- def run_async_tasks
27
- pending = @async_queue
28
- @async_queue = []
29
- pending&.each(&:call)
30
- end
31
-
32
- def run
33
- yield if block_given?
34
- while !@stopped
35
- run_async_tasks
36
- @waiting = true
37
- ring.process_completions
38
- @waiting = false
39
- end
40
- end
41
-
42
- def stop
43
- @stopped = true
44
- signal if @waiting
45
- end
46
-
47
- def timeout(delay, &block)
48
- ring.prep_timeout(interval: delay, &block)
49
- ring.submit
50
- end
51
-
52
- def interval(period, &block)
53
- ring.prep_timeout(interval: period, multishot: true, &block)
54
- ring.submit
55
- end
56
- end
57
-
58
- # exaple usage
59
- event_loop = IOUEventLoop.new
60
-
61
- trap('SIGINT') { event_loop.stop }
62
-
63
- event_loop.run do
64
- event_loop.interval(1) do
65
- puts "The time is #{Time.now}"
66
- end
67
- end
68
-
69
- puts "Stopped"
data/examples/fibers.rb DELETED
@@ -1,105 +0,0 @@
1
- require_relative '../lib/iou'
2
- require 'socket'
3
- require 'fiber'
4
-
5
- class ::Fiber
6
- attr_accessor :__op_id
7
- end
8
-
9
- class Scheduler
10
- class Cancel < Exception
11
- end
12
-
13
- attr_reader :ring
14
-
15
- def initialize
16
- @ring = IOU::Ring.new
17
- @runqueue = []
18
- end
19
-
20
- def switchpoint
21
- while true
22
- f, v = @runqueue.shift
23
- if f
24
- return f.transfer(v)
25
- end
26
-
27
- @ring.process_completions
28
- end
29
- end
30
-
31
- def fiber_wait(op_id)
32
- Fiber.current.__op_id = op_id
33
- v = switchpoint
34
- Fiber.current.__op_id = nil
35
- raise v if v.is_a?(Exception)
36
-
37
- v
38
- end
39
-
40
- def read(**args)
41
- f = Fiber.current
42
- id = ring.prep_read(**args) do |c|
43
- if c[:result] < 0
44
- @runqueue << [f, RuntimeError.new('error')]
45
- else
46
- @runqueue << [f, c[:buffer]]
47
- end
48
- end
49
- fiber_wait(id)
50
- end
51
-
52
- def write(**args)
53
- f = Fiber.current
54
- id = ring.prep_write(**args) do |c|
55
- if c[:result] < 0
56
- @runqueue << [f, RuntimeError.new('error')]
57
- else
58
- @runqueue << [f, c[:result]]
59
- end
60
- end
61
- fiber_wait(id)
62
- end
63
-
64
- def sleep(interval)
65
- f = Fiber.current
66
- id = ring.prep_timeout(interval: interval) do |c|
67
- if c[:result] == Errno::ECANCELED::Errno
68
- @runqueue << [f, c[:result]]
69
- else
70
- @runqueue << [f, c[:result]]
71
- end
72
- end
73
- fiber_wait(id)
74
- end
75
-
76
- def cancel_fiber_op(f)
77
- op_id = f.__op_id
78
- if op_id
79
- ring.prep_cancel(op_id)
80
- end
81
- end
82
-
83
- def move_on_after(interval)
84
- f = Fiber.current
85
- cancel_id = ring.prep_timeout(interval: interval) do |c|
86
- if c[:result] != Errno::ECANCELED::Errno
87
- cancel_fiber_op(f)
88
- end
89
- end
90
- v = yield
91
- ring.prep_cancel(cancel_id)
92
- v
93
- end
94
- end
95
-
96
- s = Scheduler.new
97
-
98
- puts "Going to sleep..."
99
- s.sleep 3
100
- puts "Woke up"
101
-
102
- s.move_on_after(1) do
103
- puts "Going to sleep (move on after 1 second)"
104
- s.sleep 3
105
- end
@@ -1,57 +0,0 @@
1
- require_relative '../lib/iou'
2
- require 'socket'
3
- require 'http/parser'
4
-
5
- def log(msg)
6
- # return
7
- STDERR.puts msg
8
- end
9
-
10
- socket = TCPServer.open('127.0.0.1', 1234)
11
- log 'Listening on port 1234... (multishot read)'
12
-
13
- @ring = IOU::Ring.new
14
- @bg_id = @ring.setup_buffer_ring(count: 1024, size: 4096)
15
-
16
- @ring.prep_accept(fd: socket.fileno, multishot: true) do |c|
17
- setup_connection(c[:result]) if c[:result] > 0
18
- end
19
-
20
- def setup_connection(fd)
21
- log "Connection accepted fd #{fd}"
22
-
23
- parser = Http::Parser.new
24
- parser.on_message_complete = -> {
25
- http_send_response(fd, "Hello, world!\n")
26
- }
27
-
28
- http_prep_read(fd, parser)
29
- end
30
-
31
- def http_prep_read(fd, parser)
32
- id = @ring.prep_read(fd: fd, multishot: true, buffer_group: @bg_id) do |c|
33
- if c[:result] > 0
34
- parser << c[:buffer]
35
- elsif c[:result] == 0
36
- log "Connection closed by client on fd #{fd}"
37
- else
38
- if c[:result] != -Errno::ECANCELED::Errno
39
- log "Got error #{c[:result]} on fd #{fd}, closing connection..."
40
- end
41
- @ring.prep_close(fd: fd) do |c|
42
- log "Connection closed on fd #{fd}, result #{c[:result]}"
43
- end
44
- end
45
- rescue HTTP::Parser::Error
46
- puts "Error parsing, closing connection..."
47
- @ring.prep_cancel(id)
48
- end
49
- end
50
-
51
- def http_send_response(fd, body)
52
- msg = "HTTP/1.1 200 OK\r\nContent-Type: text/plain\r\nConnection: keep-alive\r\nContent-Length: #{body.bytesize}\r\n\r\n#{body}"
53
- @ring.prep_write(fd: fd, buffer: msg)
54
- end
55
-
56
- trap('SIGINT') { exit! }
57
- @ring.process_completions_loop