uringmachine 0.12.1 → 0.13
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/CHANGELOG.md +4 -0
- data/ext/um/um.c +18 -0
- data/ext/um/um.h +3 -0
- data/ext/um/um_class.c +6 -0
- data/lib/uringmachine/version.rb +1 -1
- data/test/test_um.rb +24 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bce8525371c9f0aa2b279b815d04456573319b3eddaae14b79ddbf20ece1189f
|
4
|
+
data.tar.gz: dc1e70ca4101d607f2c04df639dabc917c379e3765a12c5440682a72cbb24316
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 258605dfe54482f5330a7795e18efa3397692b0a306cf7fd1ad6a2408fe8c7e098abca78d66baaddd78faac74aae6beeda9fe6a3d2e39ab4e196b585810bc212
|
7
|
+
data.tar.gz: 6110908bf2c3d8a404f015429835dfb585ae711f14457b785d7e298f6caf2449341ca62ab3fa560054f51c9de6031195e8ead20afabace47cfe24cdf9fd6ae48
|
data/CHANGELOG.md
CHANGED
data/ext/um/um.c
CHANGED
@@ -72,6 +72,11 @@ static inline void um_process_cqe(struct um *machine, struct io_uring_cqe *cqe)
|
|
72
72
|
// op, op->kind, op->flags, cqe->res, cqe->flags, machine->pending_count
|
73
73
|
// );
|
74
74
|
|
75
|
+
if (op->flags & OP_F_FREE_ON_COMPLETE) {
|
76
|
+
um_op_free(machine, op);
|
77
|
+
return;
|
78
|
+
}
|
79
|
+
|
75
80
|
if (unlikely((cqe->res == -ECANCELED) && (op->flags & OP_F_IGNORE_CANCELED))) return;
|
76
81
|
|
77
82
|
op->flags |= OP_F_COMPLETED;
|
@@ -390,6 +395,19 @@ VALUE um_write(struct um *machine, int fd, VALUE str, int len) {
|
|
390
395
|
return raise_if_exception(ret);
|
391
396
|
}
|
392
397
|
|
398
|
+
VALUE um_write_async(struct um *machine, int fd, VALUE str) {
|
399
|
+
struct um_op *op = um_op_alloc(machine);
|
400
|
+
memset(op, 0, sizeof(struct um_op));
|
401
|
+
op->kind = OP_WRITE_ASYNC;
|
402
|
+
op->flags = OP_F_FREE_ON_COMPLETE;
|
403
|
+
op->fiber = Qnil;
|
404
|
+
RB_OBJ_WRITE(machine->self, &op->value, str);
|
405
|
+
|
406
|
+
struct io_uring_sqe *sqe = um_get_sqe(machine, op);
|
407
|
+
io_uring_prep_write(sqe, fd, RSTRING_PTR(str), RSTRING_LEN(str), -1);
|
408
|
+
return str;
|
409
|
+
}
|
410
|
+
|
393
411
|
VALUE um_close(struct um *machine, int fd) {
|
394
412
|
struct um_op op;
|
395
413
|
um_prep_op(machine, &op, OP_CLOSE);
|
data/ext/um/um.h
CHANGED
@@ -28,6 +28,7 @@ enum op_kind {
|
|
28
28
|
OP_OPEN,
|
29
29
|
OP_READ,
|
30
30
|
OP_WRITE,
|
31
|
+
OP_WRITE_ASYNC,
|
31
32
|
OP_CLOSE,
|
32
33
|
OP_STATX,
|
33
34
|
|
@@ -59,6 +60,7 @@ enum op_kind {
|
|
59
60
|
#define OP_F_ASYNC (1U << 2) // op belongs to an AsyncOp
|
60
61
|
#define OP_F_IGNORE_CANCELED (1U << 3) // CQE with -ECANCEL should be ignored
|
61
62
|
#define OP_F_MULTISHOT (1U << 4) // op is multishot
|
63
|
+
#define OP_F_FREE_ON_COMPLETE (1U << 5) // op should be freed on receiving CQE
|
62
64
|
|
63
65
|
struct um_op_result {
|
64
66
|
__s32 res;
|
@@ -230,6 +232,7 @@ VALUE um_close(struct um *machine, int fd);
|
|
230
232
|
VALUE um_open(struct um *machine, VALUE pathname, int flags, int mode);
|
231
233
|
VALUE um_waitpid(struct um *machine, int pid, int options);
|
232
234
|
VALUE um_statx(struct um *machine, int dirfd, VALUE path, int flags, unsigned int mask);
|
235
|
+
VALUE um_write_async(struct um *machine, int fd, VALUE str);
|
233
236
|
|
234
237
|
VALUE um_accept(struct um *machine, int fd);
|
235
238
|
VALUE um_accept_each(struct um *machine, int fd);
|
data/ext/um/um_class.c
CHANGED
@@ -131,6 +131,11 @@ VALUE UM_write(int argc, VALUE *argv, VALUE self) {
|
|
131
131
|
return um_write(machine, NUM2INT(fd), buffer, bytes);
|
132
132
|
}
|
133
133
|
|
134
|
+
VALUE UM_write_async(VALUE self, VALUE fd, VALUE str) {
|
135
|
+
struct um *machine = um_get_machine(self);
|
136
|
+
return um_write_async(machine, NUM2INT(fd), str);
|
137
|
+
}
|
138
|
+
|
134
139
|
VALUE UM_statx(VALUE self, VALUE dirfd, VALUE path, VALUE flags, VALUE mask) {
|
135
140
|
struct um *machine = um_get_machine(self);
|
136
141
|
return um_statx(machine, NUM2INT(dirfd), path, NUM2INT(flags), NUM2UINT(mask));
|
@@ -348,6 +353,7 @@ void Init_UM(void) {
|
|
348
353
|
rb_define_method(cUM, "sleep", UM_sleep, 1);
|
349
354
|
rb_define_method(cUM, "periodically", UM_periodically, 1);
|
350
355
|
rb_define_method(cUM, "write", UM_write, -1);
|
356
|
+
rb_define_method(cUM, "write_async", UM_write_async, 2);
|
351
357
|
rb_define_method(cUM, "statx", UM_statx, 4);
|
352
358
|
|
353
359
|
rb_define_method(cUM, "waitpid", UM_waitpid, 2);
|
data/lib/uringmachine/version.rb
CHANGED
data/test/test_um.rb
CHANGED
@@ -532,6 +532,30 @@ class WriteTest < UMBaseTest
|
|
532
532
|
end
|
533
533
|
end
|
534
534
|
|
535
|
+
class WriteAsyncTest < UMBaseTest
|
536
|
+
def test_write_async
|
537
|
+
r, w = IO.pipe
|
538
|
+
|
539
|
+
assert_equal 0, machine.pending_count
|
540
|
+
machine.write_async(w.fileno, 'foo')
|
541
|
+
assert_equal 1, machine.pending_count
|
542
|
+
|
543
|
+
machine.snooze
|
544
|
+
assert_equal 0, machine.pending_count
|
545
|
+
assert_equal 'foo', r.readpartial(3)
|
546
|
+
end
|
547
|
+
|
548
|
+
def test_write_async_bad_fd
|
549
|
+
r, _w = IO.pipe
|
550
|
+
|
551
|
+
assert_equal 0, machine.pending_count
|
552
|
+
machine.write_async(r.fileno, 'foo')
|
553
|
+
assert_equal 1, machine.pending_count
|
554
|
+
machine.snooze
|
555
|
+
assert_equal 0, machine.pending_count
|
556
|
+
end
|
557
|
+
end
|
558
|
+
|
535
559
|
class CloseTest < UMBaseTest
|
536
560
|
def test_close
|
537
561
|
r, w = IO.pipe
|