uringmachine 0.4 → 0.5.1
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.
- checksums.yaml +4 -4
- data/.github/workflows/test.yml +2 -1
- data/CHANGELOG.md +16 -0
- data/README.md +44 -1
- data/TODO.md +12 -3
- data/examples/bm_snooze.rb +89 -0
- data/examples/bm_sqlite.rb +89 -0
- data/examples/bm_write.rb +56 -0
- data/examples/dns_client.rb +12 -0
- data/examples/http_server.rb +42 -43
- data/examples/pg.rb +85 -0
- data/examples/server_client.rb +64 -0
- data/examples/snooze.rb +44 -0
- data/examples/stream.rb +85 -0
- data/examples/write_dev_null.rb +16 -0
- data/ext/um/extconf.rb +81 -14
- data/ext/um/um.c +468 -414
- data/ext/um/um.h +149 -40
- data/ext/um/um_async_op.c +40 -0
- data/ext/um/um_async_op_class.c +136 -0
- data/ext/um/um_buffer.c +49 -0
- data/ext/um/um_class.c +176 -44
- data/ext/um/um_const.c +174 -9
- data/ext/um/um_ext.c +8 -0
- data/ext/um/um_mutex_class.c +47 -0
- data/ext/um/um_op.c +89 -111
- data/ext/um/um_queue_class.c +58 -0
- data/ext/um/um_ssl.c +850 -0
- data/ext/um/um_ssl.h +22 -0
- data/ext/um/um_ssl_class.c +138 -0
- data/ext/um/um_sync.c +273 -0
- data/ext/um/um_utils.c +1 -1
- data/lib/uringmachine/dns_resolver.rb +84 -0
- data/lib/uringmachine/ssl/context_builder.rb +96 -0
- data/lib/uringmachine/ssl.rb +394 -0
- data/lib/uringmachine/version.rb +1 -1
- data/lib/uringmachine.rb +27 -3
- data/supressions/ruby.supp +71 -0
- data/test/helper.rb +6 -0
- data/test/test_async_op.rb +119 -0
- data/test/test_ssl.rb +155 -0
- data/test/test_um.rb +464 -47
- data/uringmachine.gemspec +3 -2
- data/vendor/liburing/.gitignore +5 -0
- data/vendor/liburing/CHANGELOG +1 -0
- data/vendor/liburing/configure +32 -0
- data/vendor/liburing/examples/Makefile +1 -0
- data/vendor/liburing/examples/reg-wait.c +159 -0
- data/vendor/liburing/liburing.spec +1 -1
- data/vendor/liburing/src/include/liburing/io_uring.h +48 -2
- data/vendor/liburing/src/include/liburing.h +28 -2
- data/vendor/liburing/src/int_flags.h +10 -3
- data/vendor/liburing/src/liburing-ffi.map +13 -2
- data/vendor/liburing/src/liburing.map +9 -0
- data/vendor/liburing/src/queue.c +25 -16
- data/vendor/liburing/src/register.c +73 -4
- data/vendor/liburing/src/setup.c +46 -18
- data/vendor/liburing/src/setup.h +6 -0
- data/vendor/liburing/test/Makefile +7 -0
- data/vendor/liburing/test/cmd-discard.c +427 -0
- data/vendor/liburing/test/fifo-nonblock-read.c +69 -0
- data/vendor/liburing/test/file-exit-unreg.c +48 -0
- data/vendor/liburing/test/io_uring_passthrough.c +2 -0
- data/vendor/liburing/test/io_uring_register.c +13 -2
- data/vendor/liburing/test/napi-test.c +1 -1
- data/vendor/liburing/test/no-mmap-inval.c +1 -1
- data/vendor/liburing/test/read-mshot-empty.c +2 -0
- data/vendor/liburing/test/read-mshot-stdin.c +121 -0
- data/vendor/liburing/test/read-mshot.c +6 -0
- data/vendor/liburing/test/recvsend_bundle.c +2 -2
- data/vendor/liburing/test/reg-fd-only.c +1 -1
- data/vendor/liburing/test/reg-wait.c +251 -0
- data/vendor/liburing/test/regbuf-clone.c +458 -0
- data/vendor/liburing/test/resize-rings.c +643 -0
- data/vendor/liburing/test/rsrc_tags.c +1 -1
- data/vendor/liburing/test/sqpoll-sleep.c +39 -8
- data/vendor/liburing/test/sqwait.c +136 -0
- data/vendor/liburing/test/sync-cancel.c +8 -1
- data/vendor/liburing/test/timeout.c +13 -8
- metadata +52 -8
- data/examples/http_server_multishot.rb +0 -57
- data/examples/http_server_simpler.rb +0 -34
data/ext/um/um_class.c
CHANGED
@@ -4,13 +4,19 @@
|
|
4
4
|
VALUE cUM;
|
5
5
|
|
6
6
|
static void UM_mark(void *ptr) {
|
7
|
-
|
8
|
-
|
7
|
+
struct um *machine = ptr;
|
8
|
+
rb_gc_mark_movable(machine->self);
|
9
|
+
|
10
|
+
um_op_list_mark(machine, machine->transient_head);
|
11
|
+
um_op_list_mark(machine, machine->runqueue_head);
|
9
12
|
}
|
10
13
|
|
11
14
|
static void UM_compact(void *ptr) {
|
12
|
-
|
13
|
-
|
15
|
+
struct um *machine = ptr;
|
16
|
+
machine->self = rb_gc_location(machine->self);
|
17
|
+
|
18
|
+
um_op_list_compact(machine, machine->transient_head);
|
19
|
+
um_op_list_compact(machine, machine->runqueue_head);
|
14
20
|
}
|
15
21
|
|
16
22
|
static void UM_free(void *ptr) {
|
@@ -34,7 +40,7 @@ static VALUE UM_allocate(VALUE klass) {
|
|
34
40
|
return TypedData_Wrap_Struct(klass, &UM_type, machine);
|
35
41
|
}
|
36
42
|
|
37
|
-
inline struct um *
|
43
|
+
inline struct um *um_get_machine(VALUE self) {
|
38
44
|
struct um *machine = RTYPEDDATA_DATA(self);
|
39
45
|
if (!machine->ring_initialized)
|
40
46
|
rb_raise(rb_eRuntimeError, "Machine not initialized");
|
@@ -43,57 +49,50 @@ inline struct um *get_machine(VALUE self) {
|
|
43
49
|
|
44
50
|
VALUE UM_initialize(VALUE self) {
|
45
51
|
struct um *machine = RTYPEDDATA_DATA(self);
|
46
|
-
um_setup(machine);
|
52
|
+
um_setup(self, machine);
|
47
53
|
return self;
|
48
54
|
}
|
49
55
|
|
50
56
|
VALUE UM_setup_buffer_ring(VALUE self, VALUE size, VALUE count) {
|
51
|
-
struct um *machine =
|
57
|
+
struct um *machine = um_get_machine(self);
|
52
58
|
int bgid = um_setup_buffer_ring(machine, NUM2UINT(size), NUM2UINT(count));
|
53
59
|
return INT2NUM(bgid);
|
54
60
|
}
|
55
61
|
|
56
62
|
VALUE UM_pending_count(VALUE self) {
|
57
|
-
struct um *machine =
|
58
|
-
return
|
63
|
+
struct um *machine = um_get_machine(self);
|
64
|
+
return INT2NUM(machine->pending_count);
|
59
65
|
}
|
60
66
|
|
61
67
|
VALUE UM_snooze(VALUE self) {
|
62
|
-
struct um *machine =
|
68
|
+
struct um *machine = um_get_machine(self);
|
63
69
|
um_schedule(machine, rb_fiber_current(), Qnil);
|
64
70
|
return um_await(machine);
|
65
71
|
}
|
66
72
|
|
67
73
|
VALUE UM_yield(VALUE self) {
|
68
|
-
struct um *machine =
|
74
|
+
struct um *machine = um_get_machine(self);
|
69
75
|
return um_await(machine);
|
70
76
|
}
|
71
77
|
|
72
78
|
VALUE UM_schedule(VALUE self, VALUE fiber, VALUE value) {
|
73
|
-
struct um *machine =
|
79
|
+
struct um *machine = um_get_machine(self);
|
74
80
|
um_schedule(machine, fiber, value);
|
75
81
|
return self;
|
76
82
|
}
|
77
83
|
|
78
|
-
VALUE UM_interrupt(VALUE self, VALUE fiber, VALUE value) {
|
79
|
-
struct um *machine = get_machine(self);
|
80
|
-
um_interrupt(machine, fiber, value);
|
81
|
-
return self;
|
82
|
-
}
|
83
|
-
|
84
84
|
VALUE UM_timeout(VALUE self, VALUE interval, VALUE class) {
|
85
|
-
struct um *machine =
|
85
|
+
struct um *machine = um_get_machine(self);
|
86
86
|
return um_timeout(machine, interval, class);
|
87
87
|
}
|
88
88
|
|
89
89
|
VALUE UM_sleep(VALUE self, VALUE duration) {
|
90
|
-
struct um *machine =
|
91
|
-
um_sleep(machine, NUM2DBL(duration));
|
92
|
-
return duration;
|
90
|
+
struct um *machine = um_get_machine(self);
|
91
|
+
return um_sleep(machine, NUM2DBL(duration));
|
93
92
|
}
|
94
93
|
|
95
94
|
VALUE UM_read(int argc, VALUE *argv, VALUE self) {
|
96
|
-
struct um *machine =
|
95
|
+
struct um *machine = um_get_machine(self);
|
97
96
|
VALUE fd;
|
98
97
|
VALUE buffer;
|
99
98
|
VALUE maxlen;
|
@@ -107,12 +106,16 @@ VALUE UM_read(int argc, VALUE *argv, VALUE self) {
|
|
107
106
|
}
|
108
107
|
|
109
108
|
VALUE UM_read_each(VALUE self, VALUE fd, VALUE bgid) {
|
110
|
-
|
109
|
+
#ifdef HAVE_IO_URING_PREP_READ_MULTISHOT
|
110
|
+
struct um *machine = um_get_machine(self);
|
111
111
|
return um_read_each(machine, NUM2INT(fd), NUM2INT(bgid));
|
112
|
+
#else
|
113
|
+
rb_raise(rb_eRuntimeError, "Not supported by kernel");
|
114
|
+
#endif
|
112
115
|
}
|
113
116
|
|
114
117
|
VALUE UM_write(int argc, VALUE *argv, VALUE self) {
|
115
|
-
struct um *machine =
|
118
|
+
struct um *machine = um_get_machine(self);
|
116
119
|
VALUE fd;
|
117
120
|
VALUE buffer;
|
118
121
|
VALUE len;
|
@@ -123,27 +126,27 @@ VALUE UM_write(int argc, VALUE *argv, VALUE self) {
|
|
123
126
|
}
|
124
127
|
|
125
128
|
VALUE UM_close(VALUE self, VALUE fd) {
|
126
|
-
struct um *machine =
|
129
|
+
struct um *machine = um_get_machine(self);
|
127
130
|
return um_close(machine, NUM2INT(fd));
|
128
131
|
}
|
129
132
|
|
130
133
|
VALUE UM_accept(VALUE self, VALUE fd) {
|
131
|
-
struct um *machine =
|
134
|
+
struct um *machine = um_get_machine(self);
|
132
135
|
return um_accept(machine, NUM2INT(fd));
|
133
136
|
}
|
134
137
|
|
135
138
|
VALUE UM_accept_each(VALUE self, VALUE fd) {
|
136
|
-
struct um *machine =
|
139
|
+
struct um *machine = um_get_machine(self);
|
137
140
|
return um_accept_each(machine, NUM2INT(fd));
|
138
141
|
}
|
139
142
|
|
140
143
|
VALUE UM_socket(VALUE self, VALUE domain, VALUE type, VALUE protocol, VALUE flags) {
|
141
|
-
struct um *machine =
|
144
|
+
struct um *machine = um_get_machine(self);
|
142
145
|
return um_socket(machine, NUM2INT(domain), NUM2INT(type), NUM2INT(protocol), NUM2UINT(flags));
|
143
146
|
}
|
144
147
|
|
145
148
|
VALUE UM_connect(VALUE self, VALUE fd, VALUE host, VALUE port) {
|
146
|
-
struct um *machine =
|
149
|
+
struct um *machine = um_get_machine(self);
|
147
150
|
|
148
151
|
struct sockaddr_in addr;
|
149
152
|
memset(&addr, 0, sizeof(addr));
|
@@ -155,15 +158,20 @@ VALUE UM_connect(VALUE self, VALUE fd, VALUE host, VALUE port) {
|
|
155
158
|
}
|
156
159
|
|
157
160
|
VALUE UM_send(VALUE self, VALUE fd, VALUE buffer, VALUE len, VALUE flags) {
|
158
|
-
struct um *machine =
|
161
|
+
struct um *machine = um_get_machine(self);
|
159
162
|
return um_send(machine, NUM2INT(fd), buffer, NUM2INT(len), NUM2INT(flags));
|
160
163
|
}
|
161
164
|
|
162
165
|
VALUE UM_recv(VALUE self, VALUE fd, VALUE buffer, VALUE maxlen, VALUE flags) {
|
163
|
-
struct um *machine =
|
166
|
+
struct um *machine = um_get_machine(self);
|
164
167
|
return um_recv(machine, NUM2INT(fd), buffer, NUM2INT(maxlen), NUM2INT(flags));
|
165
168
|
}
|
166
169
|
|
170
|
+
VALUE UM_recv_each(VALUE self, VALUE fd, VALUE bgid, VALUE flags) {
|
171
|
+
struct um *machine = um_get_machine(self);
|
172
|
+
return um_recv_each(machine, NUM2INT(fd), NUM2INT(bgid), NUM2INT(flags));
|
173
|
+
}
|
174
|
+
|
167
175
|
VALUE UM_bind(VALUE self, VALUE fd, VALUE host, VALUE port) {
|
168
176
|
struct sockaddr_in addr;
|
169
177
|
memset(&addr, 0, sizeof(addr));
|
@@ -172,7 +180,7 @@ VALUE UM_bind(VALUE self, VALUE fd, VALUE host, VALUE port) {
|
|
172
180
|
addr.sin_port = htons(NUM2INT(port));
|
173
181
|
|
174
182
|
#ifdef HAVE_IO_URING_PREP_BIND
|
175
|
-
struct um *machine =
|
183
|
+
struct um *machine = um_get_machine(self);
|
176
184
|
return um_bind(machine, NUM2INT(fd), (struct sockaddr *)&addr, sizeof(addr));
|
177
185
|
#else
|
178
186
|
int res = bind(NUM2INT(fd), (struct sockaddr *)&addr, sizeof(addr));
|
@@ -184,7 +192,7 @@ VALUE UM_bind(VALUE self, VALUE fd, VALUE host, VALUE port) {
|
|
184
192
|
|
185
193
|
VALUE UM_listen(VALUE self, VALUE fd, VALUE backlog) {
|
186
194
|
#ifdef HAVE_IO_URING_PREP_LISTEN
|
187
|
-
struct um *machine =
|
195
|
+
struct um *machine = um_get_machine(self);
|
188
196
|
return um_listen(machine, NUM2INT(fd), NUM2INT(backlog));
|
189
197
|
#else
|
190
198
|
int res = listen(NUM2INT(fd), NUM2INT(backlog));
|
@@ -194,6 +202,109 @@ VALUE UM_listen(VALUE self, VALUE fd, VALUE backlog) {
|
|
194
202
|
#endif
|
195
203
|
}
|
196
204
|
|
205
|
+
static inline int numeric_value(VALUE value) {
|
206
|
+
switch (TYPE(value)) {
|
207
|
+
case T_TRUE:
|
208
|
+
return 1;
|
209
|
+
case T_FALSE:
|
210
|
+
return 0;
|
211
|
+
default:
|
212
|
+
return NUM2INT(value);
|
213
|
+
}
|
214
|
+
}
|
215
|
+
|
216
|
+
VALUE UM_getsockopt(VALUE self, VALUE fd, VALUE level, VALUE opt) {
|
217
|
+
struct um *machine = um_get_machine(self);
|
218
|
+
return um_getsockopt(machine, NUM2INT(fd), NUM2INT(level), NUM2INT(opt));
|
219
|
+
}
|
220
|
+
|
221
|
+
VALUE UM_setsockopt(VALUE self, VALUE fd, VALUE level, VALUE opt, VALUE value) {
|
222
|
+
struct um *machine = um_get_machine(self);
|
223
|
+
return um_setsockopt(machine, NUM2INT(fd), NUM2INT(level), NUM2INT(opt), numeric_value(value));
|
224
|
+
}
|
225
|
+
|
226
|
+
#ifdef HAVE_IO_URING_PREP_FUTEX
|
227
|
+
|
228
|
+
VALUE UM_mutex_synchronize(VALUE self, VALUE mutex) {
|
229
|
+
struct um *machine = um_get_machine(self);
|
230
|
+
struct um_mutex *mutex_data = Mutex_data(mutex);
|
231
|
+
return um_mutex_synchronize(machine, &mutex_data->state);
|
232
|
+
}
|
233
|
+
|
234
|
+
VALUE UM_queue_push(VALUE self, VALUE queue, VALUE value) {
|
235
|
+
struct um *machine = um_get_machine(self);
|
236
|
+
struct um_queue *que = Queue_data(queue);
|
237
|
+
return um_queue_push(machine, que, value);
|
238
|
+
}
|
239
|
+
|
240
|
+
VALUE UM_queue_pop(VALUE self, VALUE queue) {
|
241
|
+
struct um *machine = um_get_machine(self);
|
242
|
+
struct um_queue *que = Queue_data(queue);
|
243
|
+
return um_queue_pop(machine, que);
|
244
|
+
}
|
245
|
+
|
246
|
+
VALUE UM_queue_unshift(VALUE self, VALUE queue, VALUE value) {
|
247
|
+
struct um *machine = um_get_machine(self);
|
248
|
+
struct um_queue *que = Queue_data(queue);
|
249
|
+
return um_queue_unshift(machine, que, value);
|
250
|
+
}
|
251
|
+
|
252
|
+
VALUE UM_queue_shift(VALUE self, VALUE queue) {
|
253
|
+
struct um *machine = um_get_machine(self);
|
254
|
+
struct um_queue *que = Queue_data(queue);
|
255
|
+
return um_queue_shift(machine, que);
|
256
|
+
}
|
257
|
+
|
258
|
+
#endif
|
259
|
+
|
260
|
+
struct um_open_ctx {
|
261
|
+
VALUE self;
|
262
|
+
VALUE fd;
|
263
|
+
};
|
264
|
+
|
265
|
+
VALUE UM_open_ensure(VALUE arg) {
|
266
|
+
struct um_open_ctx *ctx = (struct um_open_ctx *)arg;
|
267
|
+
UM_close(ctx->self, ctx->fd);
|
268
|
+
return ctx->self;
|
269
|
+
}
|
270
|
+
|
271
|
+
VALUE UM_open(VALUE self, VALUE pathname, VALUE flags) {
|
272
|
+
struct um *machine = um_get_machine(self);
|
273
|
+
// TODO: take optional perm (mode) arg
|
274
|
+
VALUE fd = um_open(machine, pathname, NUM2INT(flags), 0666);
|
275
|
+
if (rb_block_given_p()) {
|
276
|
+
struct um_open_ctx ctx = { self, fd };
|
277
|
+
return rb_ensure(rb_yield, fd, UM_open_ensure, (VALUE)&ctx);
|
278
|
+
}
|
279
|
+
else
|
280
|
+
return fd;
|
281
|
+
}
|
282
|
+
|
283
|
+
VALUE UM_waitpid(VALUE self, VALUE pid, VALUE options) {
|
284
|
+
struct um *machine = um_get_machine(self);
|
285
|
+
return um_waitpid(machine, NUM2INT(pid), NUM2INT(options));
|
286
|
+
}
|
287
|
+
|
288
|
+
VALUE UM_prep_timeout(VALUE self, VALUE interval) {
|
289
|
+
struct um *machine = um_get_machine(self);
|
290
|
+
return um_prep_timeout(machine, NUM2DBL(interval));
|
291
|
+
}
|
292
|
+
|
293
|
+
VALUE UM_pipe(VALUE self) {
|
294
|
+
int fds[2];
|
295
|
+
int ret = pipe(fds);
|
296
|
+
if (ret) {
|
297
|
+
int e = errno;
|
298
|
+
rb_syserr_fail(e, strerror(e));
|
299
|
+
}
|
300
|
+
|
301
|
+
return rb_ary_new_from_args(2, INT2NUM(fds[0]), INT2NUM(fds[1]));
|
302
|
+
}
|
303
|
+
|
304
|
+
VALUE UM_kernel_version(VALUE self) {
|
305
|
+
return INT2NUM(UM_KERNEL_VERSION);
|
306
|
+
}
|
307
|
+
|
197
308
|
void Init_UM(void) {
|
198
309
|
rb_ext_ractor_safe(true);
|
199
310
|
|
@@ -201,29 +312,50 @@ void Init_UM(void) {
|
|
201
312
|
rb_define_alloc_func(cUM, UM_allocate);
|
202
313
|
|
203
314
|
rb_define_method(cUM, "initialize", UM_initialize, 0);
|
204
|
-
rb_define_method(cUM, "setup_buffer_ring", UM_setup_buffer_ring, 2);
|
205
315
|
rb_define_method(cUM, "pending_count", UM_pending_count, 0);
|
316
|
+
rb_define_method(cUM, "setup_buffer_ring", UM_setup_buffer_ring, 2);
|
317
|
+
|
318
|
+
rb_define_singleton_method(cUM, "pipe", UM_pipe, 0);
|
319
|
+
rb_define_singleton_method(cUM, "kernel_version", UM_kernel_version, 0);
|
320
|
+
|
206
321
|
|
207
|
-
rb_define_method(cUM, "snooze", UM_snooze, 0);
|
208
|
-
rb_define_method(cUM, "yield", UM_yield, 0);
|
209
322
|
rb_define_method(cUM, "schedule", UM_schedule, 2);
|
210
|
-
rb_define_method(cUM, "
|
323
|
+
rb_define_method(cUM, "snooze", UM_snooze, 0);
|
211
324
|
rb_define_method(cUM, "timeout", UM_timeout, 2);
|
325
|
+
rb_define_method(cUM, "yield", UM_yield, 0);
|
212
326
|
|
213
|
-
rb_define_method(cUM, "
|
327
|
+
rb_define_method(cUM, "close", UM_close, 1);
|
328
|
+
rb_define_method(cUM, "open", UM_open, 2);
|
214
329
|
rb_define_method(cUM, "read", UM_read, -1);
|
215
330
|
rb_define_method(cUM, "read_each", UM_read_each, 2);
|
331
|
+
rb_define_method(cUM, "sleep", UM_sleep, 1);
|
216
332
|
rb_define_method(cUM, "write", UM_write, -1);
|
217
|
-
|
333
|
+
|
334
|
+
rb_define_method(cUM, "waitpid", UM_waitpid, 2);
|
218
335
|
|
219
336
|
rb_define_method(cUM, "accept", UM_accept, 1);
|
220
337
|
rb_define_method(cUM, "accept_each", UM_accept_each, 1);
|
221
|
-
rb_define_method(cUM, "socket", UM_socket, 4);
|
222
|
-
rb_define_method(cUM, "connect", UM_connect, 3);
|
223
|
-
rb_define_method(cUM, "send", UM_send, 4);
|
224
|
-
rb_define_method(cUM, "recv", UM_recv, 4);
|
225
338
|
rb_define_method(cUM, "bind", UM_bind, 3);
|
339
|
+
rb_define_method(cUM, "connect", UM_connect, 3);
|
340
|
+
rb_define_method(cUM, "getsockopt", UM_getsockopt, 3);
|
226
341
|
rb_define_method(cUM, "listen", UM_listen, 2);
|
342
|
+
rb_define_method(cUM, "recv", UM_recv, 4);
|
343
|
+
rb_define_method(cUM, "recv_each", UM_recv_each, 3);
|
344
|
+
rb_define_method(cUM, "send", UM_send, 4);
|
345
|
+
rb_define_method(cUM, "setsockopt", UM_setsockopt, 4);
|
346
|
+
rb_define_method(cUM, "socket", UM_socket, 4);
|
347
|
+
|
348
|
+
rb_define_method(cUM, "prep_timeout", UM_prep_timeout, 1);
|
349
|
+
|
350
|
+
#ifdef HAVE_IO_URING_PREP_FUTEX
|
351
|
+
rb_define_method(cUM, "pop", UM_queue_pop, 1);
|
352
|
+
rb_define_method(cUM, "push", UM_queue_push, 2);
|
353
|
+
rb_define_method(cUM, "shift", UM_queue_shift, 1);
|
354
|
+
rb_define_method(cUM, "synchronize", UM_mutex_synchronize, 1);
|
355
|
+
rb_define_method(cUM, "unshift", UM_queue_unshift, 2);
|
356
|
+
#endif
|
357
|
+
|
358
|
+
// Init_micro_ssl(cUM);
|
227
359
|
|
228
360
|
um_define_net_constants(cUM);
|
229
361
|
}
|
data/ext/um/um_const.c
CHANGED
@@ -1,4 +1,8 @@
|
|
1
1
|
#include "ruby.h"
|
2
|
+
|
3
|
+
#include <fcntl.h>
|
4
|
+
#include <sys/wait.h>
|
5
|
+
|
2
6
|
#include <arpa/inet.h>
|
3
7
|
#include <sys/types.h>
|
4
8
|
#include <sys/socket.h>
|
@@ -12,6 +16,43 @@
|
|
12
16
|
#define DEF_CONST_INT(mod, v) rb_define_const(mod, #v, INT2NUM(v))
|
13
17
|
|
14
18
|
void um_define_net_constants(VALUE mod) {
|
19
|
+
DEF_CONST_INT(mod, MSG_CONFIRM);
|
20
|
+
DEF_CONST_INT(mod, MSG_DONTROUTE);
|
21
|
+
DEF_CONST_INT(mod, MSG_DONTWAIT);
|
22
|
+
DEF_CONST_INT(mod, MSG_EOR);
|
23
|
+
DEF_CONST_INT(mod, MSG_ERRQUEUE);
|
24
|
+
DEF_CONST_INT(mod, MSG_FASTOPEN);
|
25
|
+
DEF_CONST_INT(mod, MSG_MORE);
|
26
|
+
DEF_CONST_INT(mod, MSG_NOSIGNAL);
|
27
|
+
DEF_CONST_INT(mod, MSG_OOB);
|
28
|
+
DEF_CONST_INT(mod, MSG_PEEK);
|
29
|
+
DEF_CONST_INT(mod, MSG_TRUNC);
|
30
|
+
DEF_CONST_INT(mod, MSG_WAITALL);
|
31
|
+
|
32
|
+
DEF_CONST_INT(mod, O_APPEND);
|
33
|
+
DEF_CONST_INT(mod, O_CLOEXEC);
|
34
|
+
DEF_CONST_INT(mod, O_CREAT);
|
35
|
+
DEF_CONST_INT(mod, O_DIRECT);
|
36
|
+
DEF_CONST_INT(mod, O_DIRECTORY);
|
37
|
+
DEF_CONST_INT(mod, O_DSYNC);
|
38
|
+
DEF_CONST_INT(mod, O_EXCL);
|
39
|
+
DEF_CONST_INT(mod, O_NOCTTY);
|
40
|
+
DEF_CONST_INT(mod, O_NOFOLLOW);
|
41
|
+
DEF_CONST_INT(mod, O_PATH);
|
42
|
+
DEF_CONST_INT(mod, O_RDONLY);
|
43
|
+
DEF_CONST_INT(mod, O_RDWR);
|
44
|
+
DEF_CONST_INT(mod, O_SYNC);
|
45
|
+
DEF_CONST_INT(mod, O_TMPFILE);
|
46
|
+
DEF_CONST_INT(mod, O_TRUNC);
|
47
|
+
DEF_CONST_INT(mod, O_WRONLY);
|
48
|
+
|
49
|
+
DEF_CONST_INT(mod, WNOHANG);
|
50
|
+
DEF_CONST_INT(mod, WUNTRACED);
|
51
|
+
DEF_CONST_INT(mod, WCONTINUED);
|
52
|
+
DEF_CONST_INT(mod, WEXITED);
|
53
|
+
DEF_CONST_INT(mod, WSTOPPED);
|
54
|
+
DEF_CONST_INT(mod, WNOWAIT);
|
55
|
+
|
15
56
|
DEF_CONST_INT(mod, SOCK_STREAM);
|
16
57
|
DEF_CONST_INT(mod, SOCK_DGRAM);
|
17
58
|
DEF_CONST_INT(mod, SOCK_RAW);
|
@@ -35,13 +76,6 @@ void um_define_net_constants(VALUE mod) {
|
|
35
76
|
DEF_CONST_INT(mod, AF_MAX);
|
36
77
|
DEF_CONST_INT(mod, PF_MAX);
|
37
78
|
|
38
|
-
DEF_CONST_INT(mod, MSG_OOB);
|
39
|
-
DEF_CONST_INT(mod, MSG_PEEK);
|
40
|
-
DEF_CONST_INT(mod, MSG_DONTROUTE);
|
41
|
-
DEF_CONST_INT(mod, MSG_WAITALL);
|
42
|
-
DEF_CONST_INT(mod, MSG_DONTWAIT);
|
43
|
-
DEF_CONST_INT(mod, MSG_MORE);
|
44
|
-
|
45
79
|
DEF_CONST_INT(mod, SOL_SOCKET);
|
46
80
|
DEF_CONST_INT(mod, SOL_IP);
|
47
81
|
|
@@ -117,7 +151,7 @@ void um_define_net_constants(VALUE mod) {
|
|
117
151
|
DEF_CONST_INT(mod, TCP_WINDOW_CLAMP);
|
118
152
|
DEF_CONST_INT(mod, TCP_FASTOPEN);
|
119
153
|
DEF_CONST_INT(mod, TCP_CONGESTION);
|
120
|
-
DEF_CONST_INT(mod, TCP_COOKIE_TRANSACTIONS);
|
154
|
+
// DEF_CONST_INT(mod, TCP_COOKIE_TRANSACTIONS);
|
121
155
|
DEF_CONST_INT(mod, TCP_QUEUE_SEQ);
|
122
156
|
DEF_CONST_INT(mod, TCP_REPAIR);
|
123
157
|
DEF_CONST_INT(mod, TCP_REPAIR_OPTIONS);
|
@@ -181,4 +215,135 @@ void um_define_net_constants(VALUE mod) {
|
|
181
215
|
DEF_CONST_INT(mod, IF_NAMESIZE);
|
182
216
|
|
183
217
|
DEF_CONST_INT(mod, SOMAXCONN);
|
184
|
-
|
218
|
+
|
219
|
+
DEF_CONST_INT(mod, EPERM);
|
220
|
+
DEF_CONST_INT(mod, ENOENT);
|
221
|
+
DEF_CONST_INT(mod, ESRCH);
|
222
|
+
DEF_CONST_INT(mod, EINTR);
|
223
|
+
DEF_CONST_INT(mod, EIO);
|
224
|
+
DEF_CONST_INT(mod, ENXIO);
|
225
|
+
DEF_CONST_INT(mod, E2BIG);
|
226
|
+
DEF_CONST_INT(mod, ENOEXEC);
|
227
|
+
DEF_CONST_INT(mod, EBADF);
|
228
|
+
DEF_CONST_INT(mod, ECHILD);
|
229
|
+
DEF_CONST_INT(mod, EAGAIN);
|
230
|
+
DEF_CONST_INT(mod, ENOMEM);
|
231
|
+
DEF_CONST_INT(mod, EACCES);
|
232
|
+
DEF_CONST_INT(mod, EFAULT);
|
233
|
+
DEF_CONST_INT(mod, ENOTBLK);
|
234
|
+
DEF_CONST_INT(mod, EBUSY);
|
235
|
+
DEF_CONST_INT(mod, EEXIST);
|
236
|
+
DEF_CONST_INT(mod, EXDEV);
|
237
|
+
DEF_CONST_INT(mod, ENODEV);
|
238
|
+
DEF_CONST_INT(mod, ENOTDIR);
|
239
|
+
DEF_CONST_INT(mod, EISDIR);
|
240
|
+
DEF_CONST_INT(mod, EINVAL);
|
241
|
+
DEF_CONST_INT(mod, ENFILE);
|
242
|
+
DEF_CONST_INT(mod, EMFILE);
|
243
|
+
DEF_CONST_INT(mod, ENOTTY);
|
244
|
+
DEF_CONST_INT(mod, ETXTBSY);
|
245
|
+
DEF_CONST_INT(mod, EFBIG);
|
246
|
+
DEF_CONST_INT(mod, ENOSPC);
|
247
|
+
DEF_CONST_INT(mod, ESPIPE);
|
248
|
+
DEF_CONST_INT(mod, EROFS);
|
249
|
+
DEF_CONST_INT(mod, EMLINK);
|
250
|
+
DEF_CONST_INT(mod, EPIPE);
|
251
|
+
DEF_CONST_INT(mod, EDOM);
|
252
|
+
DEF_CONST_INT(mod, ERANGE);
|
253
|
+
DEF_CONST_INT(mod, EDEADLK);
|
254
|
+
DEF_CONST_INT(mod, ENAMETOOLONG);
|
255
|
+
DEF_CONST_INT(mod, ENOLCK);
|
256
|
+
DEF_CONST_INT(mod, ENOSYS);
|
257
|
+
DEF_CONST_INT(mod, ENOTEMPTY);
|
258
|
+
DEF_CONST_INT(mod, ELOOP);
|
259
|
+
DEF_CONST_INT(mod, ENOMSG);
|
260
|
+
DEF_CONST_INT(mod, EIDRM);
|
261
|
+
DEF_CONST_INT(mod, ECHRNG);
|
262
|
+
DEF_CONST_INT(mod, EL2NSYNC);
|
263
|
+
DEF_CONST_INT(mod, EL3HLT);
|
264
|
+
DEF_CONST_INT(mod, EL3RST);
|
265
|
+
DEF_CONST_INT(mod, ELNRNG);
|
266
|
+
DEF_CONST_INT(mod, EUNATCH);
|
267
|
+
DEF_CONST_INT(mod, ENOCSI);
|
268
|
+
DEF_CONST_INT(mod, EL2HLT);
|
269
|
+
DEF_CONST_INT(mod, EBADE);
|
270
|
+
DEF_CONST_INT(mod, EBADR);
|
271
|
+
DEF_CONST_INT(mod, EXFULL);
|
272
|
+
DEF_CONST_INT(mod, ENOANO);
|
273
|
+
DEF_CONST_INT(mod, EBADRQC);
|
274
|
+
DEF_CONST_INT(mod, EBADSLT);
|
275
|
+
DEF_CONST_INT(mod, EBFONT);
|
276
|
+
DEF_CONST_INT(mod, ENOSTR);
|
277
|
+
DEF_CONST_INT(mod, ENODATA);
|
278
|
+
DEF_CONST_INT(mod, ETIME);
|
279
|
+
DEF_CONST_INT(mod, ENOSR);
|
280
|
+
DEF_CONST_INT(mod, ENONET);
|
281
|
+
DEF_CONST_INT(mod, ENOPKG);
|
282
|
+
DEF_CONST_INT(mod, EREMOTE);
|
283
|
+
DEF_CONST_INT(mod, ENOLINK);
|
284
|
+
DEF_CONST_INT(mod, EADV);
|
285
|
+
DEF_CONST_INT(mod, ESRMNT);
|
286
|
+
DEF_CONST_INT(mod, ECOMM);
|
287
|
+
DEF_CONST_INT(mod, EPROTO);
|
288
|
+
DEF_CONST_INT(mod, EMULTIHOP);
|
289
|
+
DEF_CONST_INT(mod, EDOTDOT);
|
290
|
+
DEF_CONST_INT(mod, EBADMSG);
|
291
|
+
DEF_CONST_INT(mod, EOVERFLOW);
|
292
|
+
DEF_CONST_INT(mod, ENOTUNIQ);
|
293
|
+
DEF_CONST_INT(mod, EBADFD);
|
294
|
+
DEF_CONST_INT(mod, EREMCHG);
|
295
|
+
DEF_CONST_INT(mod, ELIBACC);
|
296
|
+
DEF_CONST_INT(mod, ELIBBAD);
|
297
|
+
DEF_CONST_INT(mod, ELIBSCN);
|
298
|
+
DEF_CONST_INT(mod, ELIBMAX);
|
299
|
+
DEF_CONST_INT(mod, ELIBEXEC);
|
300
|
+
DEF_CONST_INT(mod, EILSEQ);
|
301
|
+
DEF_CONST_INT(mod, ERESTART);
|
302
|
+
DEF_CONST_INT(mod, ESTRPIPE);
|
303
|
+
DEF_CONST_INT(mod, EUSERS);
|
304
|
+
DEF_CONST_INT(mod, ENOTSOCK);
|
305
|
+
DEF_CONST_INT(mod, EDESTADDRREQ);
|
306
|
+
DEF_CONST_INT(mod, EMSGSIZE);
|
307
|
+
DEF_CONST_INT(mod, EPROTOTYPE);
|
308
|
+
DEF_CONST_INT(mod, ENOPROTOOPT);
|
309
|
+
DEF_CONST_INT(mod, EPROTONOSUPPORT);
|
310
|
+
DEF_CONST_INT(mod, ESOCKTNOSUPPORT);
|
311
|
+
DEF_CONST_INT(mod, EOPNOTSUPP);
|
312
|
+
DEF_CONST_INT(mod, EPFNOSUPPORT);
|
313
|
+
DEF_CONST_INT(mod, EAFNOSUPPORT);
|
314
|
+
DEF_CONST_INT(mod, EADDRINUSE);
|
315
|
+
DEF_CONST_INT(mod, EADDRNOTAVAIL);
|
316
|
+
DEF_CONST_INT(mod, ENETDOWN);
|
317
|
+
DEF_CONST_INT(mod, ENETUNREACH);
|
318
|
+
DEF_CONST_INT(mod, ENETRESET);
|
319
|
+
DEF_CONST_INT(mod, ECONNABORTED);
|
320
|
+
DEF_CONST_INT(mod, ECONNRESET);
|
321
|
+
DEF_CONST_INT(mod, ENOBUFS);
|
322
|
+
DEF_CONST_INT(mod, EISCONN);
|
323
|
+
DEF_CONST_INT(mod, ENOTCONN);
|
324
|
+
DEF_CONST_INT(mod, ESHUTDOWN);
|
325
|
+
DEF_CONST_INT(mod, ETOOMANYREFS);
|
326
|
+
DEF_CONST_INT(mod, ETIMEDOUT);
|
327
|
+
DEF_CONST_INT(mod, ECONNREFUSED);
|
328
|
+
DEF_CONST_INT(mod, EHOSTDOWN);
|
329
|
+
DEF_CONST_INT(mod, EHOSTUNREACH);
|
330
|
+
DEF_CONST_INT(mod, EALREADY);
|
331
|
+
DEF_CONST_INT(mod, EINPROGRESS);
|
332
|
+
DEF_CONST_INT(mod, ESTALE);
|
333
|
+
DEF_CONST_INT(mod, EUCLEAN);
|
334
|
+
DEF_CONST_INT(mod, ENOTNAM);
|
335
|
+
DEF_CONST_INT(mod, ENAVAIL);
|
336
|
+
DEF_CONST_INT(mod, EISNAM);
|
337
|
+
DEF_CONST_INT(mod, EREMOTEIO);
|
338
|
+
DEF_CONST_INT(mod, EDQUOT);
|
339
|
+
DEF_CONST_INT(mod, ENOMEDIUM);
|
340
|
+
DEF_CONST_INT(mod, EMEDIUMTYPE);
|
341
|
+
DEF_CONST_INT(mod, ECANCELED);
|
342
|
+
DEF_CONST_INT(mod, ENOKEY);
|
343
|
+
DEF_CONST_INT(mod, EKEYEXPIRED);
|
344
|
+
DEF_CONST_INT(mod, EKEYREVOKED);
|
345
|
+
DEF_CONST_INT(mod, EKEYREJECTED);
|
346
|
+
DEF_CONST_INT(mod, EOWNERDEAD);
|
347
|
+
DEF_CONST_INT(mod, ENOTRECOVERABLE);
|
348
|
+
|
349
|
+
}
|
data/ext/um/um_ext.c
CHANGED
@@ -0,0 +1,47 @@
|
|
1
|
+
#include "um.h"
|
2
|
+
#include <stdlib.h>
|
3
|
+
|
4
|
+
VALUE cMutex;
|
5
|
+
|
6
|
+
static void Mutex_mark(void *ptr) {
|
7
|
+
struct um_mutex *mutex = ptr;
|
8
|
+
rb_gc_mark_movable(mutex->self);
|
9
|
+
}
|
10
|
+
|
11
|
+
static void Mutex_compact(void *ptr) {
|
12
|
+
struct um_mutex *mutex = ptr;
|
13
|
+
mutex->self = rb_gc_location(mutex->self);
|
14
|
+
}
|
15
|
+
|
16
|
+
static size_t Mutex_size(const void *ptr) {
|
17
|
+
return sizeof(struct um_mutex);
|
18
|
+
}
|
19
|
+
|
20
|
+
static const rb_data_type_t Mutex_type = {
|
21
|
+
"UringMachineMutex",
|
22
|
+
{Mutex_mark, free, Mutex_size, Mutex_compact},
|
23
|
+
0, 0, RUBY_TYPED_FREE_IMMEDIATELY | RUBY_TYPED_WB_PROTECTED
|
24
|
+
};
|
25
|
+
|
26
|
+
static VALUE Mutex_allocate(VALUE klass) {
|
27
|
+
struct um_mutex *mutex = malloc(sizeof(struct um_mutex));
|
28
|
+
return TypedData_Wrap_Struct(klass, &Mutex_type, mutex);
|
29
|
+
}
|
30
|
+
|
31
|
+
inline struct um_mutex *Mutex_data(VALUE self) {
|
32
|
+
return RTYPEDDATA_DATA(self);
|
33
|
+
}
|
34
|
+
|
35
|
+
VALUE Mutex_initialize(VALUE self) {
|
36
|
+
struct um_mutex *mutex = Mutex_data(self);
|
37
|
+
mutex->self = self;
|
38
|
+
um_mutex_init(mutex);
|
39
|
+
return self;
|
40
|
+
}
|
41
|
+
|
42
|
+
void Init_Mutex(void) {
|
43
|
+
cMutex = rb_define_class_under(cUM, "Mutex", rb_cObject);
|
44
|
+
rb_define_alloc_func(cMutex, Mutex_allocate);
|
45
|
+
|
46
|
+
rb_define_method(cMutex, "initialize", Mutex_initialize, 0);
|
47
|
+
}
|