event 0.4.2 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/ext/event/Makefile +267 -0
- data/ext/event/backend.o +0 -0
- data/ext/event/backend/backend.c +178 -0
- data/ext/event/backend/backend.h +84 -1
- data/ext/event/backend/epoll.c +251 -13
- data/ext/event/backend/kqueue.c +288 -18
- data/ext/event/backend/pidfd.c +36 -0
- data/ext/event/backend/uring.c +336 -130
- data/ext/event/event.bundle +0 -0
- data/ext/event/event.c +3 -0
- data/ext/event/event.h +3 -3
- data/ext/event/event.o +0 -0
- data/ext/event/extconf.h +4 -0
- data/ext/event/extconf.rb +8 -1
- data/ext/event/kqueue.o +0 -0
- data/ext/event/mkmf.log +195 -0
- data/lib/event/backend/select.rb +90 -1
- data/lib/event/version.rb +1 -1
- metadata +12 -3
Binary file
|
data/ext/event/event.c
CHANGED
@@ -19,6 +19,7 @@
|
|
19
19
|
// THE SOFTWARE.
|
20
20
|
|
21
21
|
#include "event.h"
|
22
|
+
#include "backend/backend.h"
|
22
23
|
|
23
24
|
VALUE Event = Qnil;
|
24
25
|
VALUE Event_Backend = Qnil;
|
@@ -32,6 +33,8 @@ void Init_event()
|
|
32
33
|
Event = rb_define_module("Event");
|
33
34
|
Event_Backend = rb_define_module_under(Event, "Backend");
|
34
35
|
|
36
|
+
Init_Event_Backend(Event_Backend);
|
37
|
+
|
35
38
|
#ifdef EVENT_BACKEND_URING
|
36
39
|
Init_Event_Backend_URing(Event_Backend);
|
37
40
|
#endif
|
data/ext/event/event.h
CHANGED
@@ -26,14 +26,14 @@
|
|
26
26
|
|
27
27
|
void Init_event();
|
28
28
|
|
29
|
-
#
|
29
|
+
#ifdef HAVE_LIBURING_H
|
30
30
|
#include "backend/uring.h"
|
31
31
|
#endif
|
32
32
|
|
33
|
-
#
|
33
|
+
#ifdef HAVE_SYS_EPOLL_H
|
34
34
|
#include "backend/epoll.h"
|
35
35
|
#endif
|
36
36
|
|
37
|
-
#
|
37
|
+
#ifdef HAVE_SYS_EVENT_H
|
38
38
|
#include "backend/kqueue.h"
|
39
39
|
#endif
|
data/ext/event/event.o
ADDED
Binary file
|
data/ext/event/extconf.h
ADDED
data/ext/event/extconf.rb
CHANGED
@@ -30,9 +30,11 @@ dir_config(extension_name)
|
|
30
30
|
|
31
31
|
$CFLAGS << " -Wall"
|
32
32
|
|
33
|
-
$srcs = ["event.c"]
|
33
|
+
$srcs = ["event.c", "backend/backend.c"]
|
34
34
|
$VPATH << "$(srcdir)/backend"
|
35
35
|
|
36
|
+
have_func('&rb_fiber_transfer')
|
37
|
+
|
36
38
|
if have_library('uring') and have_header('liburing.h')
|
37
39
|
$srcs << "backend/uring.c"
|
38
40
|
end
|
@@ -45,6 +47,11 @@ if have_header('sys/event.h')
|
|
45
47
|
$srcs << "backend/kqueue.c"
|
46
48
|
end
|
47
49
|
|
50
|
+
have_func("rb_io_descriptor")
|
51
|
+
have_func("&rb_process_status_wait")
|
52
|
+
|
53
|
+
have_header('ruby/io/buffer.h')
|
54
|
+
|
48
55
|
create_header
|
49
56
|
|
50
57
|
# Generate the makefile to compile the native binary into `lib`:
|
data/ext/event/kqueue.o
ADDED
Binary file
|
data/ext/event/mkmf.log
ADDED
@@ -0,0 +1,195 @@
|
|
1
|
+
have_func: checking for &rb_fiber_transfer()... -------------------- no
|
2
|
+
|
3
|
+
"clang -fdeclspec -o conftest -I/Users/samuel/.rubies/ruby-3.0.1/include/ruby-3.0.0/x86_64-darwin20 -I/Users/samuel/.rubies/ruby-3.0.1/include/ruby-3.0.0/ruby/backward -I/Users/samuel/.rubies/ruby-3.0.1/include/ruby-3.0.0 -I. -I/opt/local/include -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT -O3 -ggdb3 -Wall -Wextra -Wdeprecated-declarations -Wdivision-by-zero -Wimplicit-function-declaration -Wimplicit-int -Wmisleading-indentation -Wpointer-arith -Wshorten-64-to-32 -Wwrite-strings -Wmissing-noreturn -Wno-constant-logical-operand -Wno-long-long -Wno-missing-field-initializers -Wno-overlength-strings -Wno-parentheses-equality -Wno-self-assign -Wno-tautological-compare -Wno-unused-parameter -Wno-unused-value -Wunused-variable -Wextra-tokens -pipe -Wall conftest.c -L. -L/Users/samuel/.rubies/ruby-3.0.1/lib -L/opt/local/lib -L. -fstack-protector-strong -L/opt/local/lib -lruby.3.0-static -framework Security -framework Foundation -lpthread -lgmp -ldl -lobjc "
|
4
|
+
checked program was:
|
5
|
+
/* begin */
|
6
|
+
1: #include "ruby.h"
|
7
|
+
2:
|
8
|
+
3: int main(int argc, char **argv)
|
9
|
+
4: {
|
10
|
+
5: return !!argv[argc];
|
11
|
+
6: }
|
12
|
+
/* end */
|
13
|
+
|
14
|
+
"clang -fdeclspec -o conftest -I/Users/samuel/.rubies/ruby-3.0.1/include/ruby-3.0.0/x86_64-darwin20 -I/Users/samuel/.rubies/ruby-3.0.1/include/ruby-3.0.0/ruby/backward -I/Users/samuel/.rubies/ruby-3.0.1/include/ruby-3.0.0 -I. -I/opt/local/include -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT -O3 -ggdb3 -Wall -Wextra -Wdeprecated-declarations -Wdivision-by-zero -Wimplicit-function-declaration -Wimplicit-int -Wmisleading-indentation -Wpointer-arith -Wshorten-64-to-32 -Wwrite-strings -Wmissing-noreturn -Wno-constant-logical-operand -Wno-long-long -Wno-missing-field-initializers -Wno-overlength-strings -Wno-parentheses-equality -Wno-self-assign -Wno-tautological-compare -Wno-unused-parameter -Wno-unused-value -Wunused-variable -Wextra-tokens -pipe -Wall conftest.c -L. -L/Users/samuel/.rubies/ruby-3.0.1/lib -L/opt/local/lib -L. -fstack-protector-strong -L/opt/local/lib -lruby.3.0-static -framework Security -framework Foundation -lpthread -lgmp -ldl -lobjc "
|
15
|
+
conftest.c:14:76: error: use of undeclared identifier 'rb_fiber_transfer'
|
16
|
+
int t(void) { const volatile void *volatile p; p = (const volatile void *)&rb_fiber_transfer; return !p; }
|
17
|
+
^
|
18
|
+
1 error generated.
|
19
|
+
checked program was:
|
20
|
+
/* begin */
|
21
|
+
1: #include "ruby.h"
|
22
|
+
2:
|
23
|
+
3: /*top*/
|
24
|
+
4: extern int t(void);
|
25
|
+
5: int main(int argc, char **argv)
|
26
|
+
6: {
|
27
|
+
7: if (argc > 1000000) {
|
28
|
+
8: int (* volatile tp)(void)=(int (*)(void))&t;
|
29
|
+
9: printf("%d", (*tp)());
|
30
|
+
10: }
|
31
|
+
11:
|
32
|
+
12: return !!argv[argc];
|
33
|
+
13: }
|
34
|
+
14: int t(void) { const volatile void *volatile p; p = (const volatile void *)&rb_fiber_transfer; return !p; }
|
35
|
+
/* end */
|
36
|
+
|
37
|
+
--------------------
|
38
|
+
|
39
|
+
have_library: checking for -luring... -------------------- no
|
40
|
+
|
41
|
+
"clang -fdeclspec -o conftest -I/Users/samuel/.rubies/ruby-3.0.1/include/ruby-3.0.0/x86_64-darwin20 -I/Users/samuel/.rubies/ruby-3.0.1/include/ruby-3.0.0/ruby/backward -I/Users/samuel/.rubies/ruby-3.0.1/include/ruby-3.0.0 -I. -I/opt/local/include -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT -O3 -ggdb3 -Wall -Wextra -Wdeprecated-declarations -Wdivision-by-zero -Wimplicit-function-declaration -Wimplicit-int -Wmisleading-indentation -Wpointer-arith -Wshorten-64-to-32 -Wwrite-strings -Wmissing-noreturn -Wno-constant-logical-operand -Wno-long-long -Wno-missing-field-initializers -Wno-overlength-strings -Wno-parentheses-equality -Wno-self-assign -Wno-tautological-compare -Wno-unused-parameter -Wno-unused-value -Wunused-variable -Wextra-tokens -pipe -Wall conftest.c -L. -L/Users/samuel/.rubies/ruby-3.0.1/lib -L/opt/local/lib -L. -fstack-protector-strong -L/opt/local/lib -lruby.3.0-static -framework Security -framework Foundation -lpthread -lgmp -ldl -lobjc -luring "
|
42
|
+
ld: library not found for -luring
|
43
|
+
clang: error: linker command failed with exit code 1 (use -v to see invocation)
|
44
|
+
checked program was:
|
45
|
+
/* begin */
|
46
|
+
1: #include "ruby.h"
|
47
|
+
2:
|
48
|
+
3: /*top*/
|
49
|
+
4: extern int t(void);
|
50
|
+
5: int main(int argc, char **argv)
|
51
|
+
6: {
|
52
|
+
7: if (argc > 1000000) {
|
53
|
+
8: int (* volatile tp)(void)=(int (*)(void))&t;
|
54
|
+
9: printf("%d", (*tp)());
|
55
|
+
10: }
|
56
|
+
11:
|
57
|
+
12: return !!argv[argc];
|
58
|
+
13: }
|
59
|
+
14:
|
60
|
+
15: int t(void) { ; return 0; }
|
61
|
+
/* end */
|
62
|
+
|
63
|
+
--------------------
|
64
|
+
|
65
|
+
have_header: checking for sys/epoll.h... -------------------- no
|
66
|
+
|
67
|
+
"clang -E -I/Users/samuel/.rubies/ruby-3.0.1/include/ruby-3.0.0/x86_64-darwin20 -I/Users/samuel/.rubies/ruby-3.0.1/include/ruby-3.0.0/ruby/backward -I/Users/samuel/.rubies/ruby-3.0.1/include/ruby-3.0.0 -I. -I/opt/local/include -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT -O3 -ggdb3 -Wall -Wextra -Wdeprecated-declarations -Wdivision-by-zero -Wimplicit-function-declaration -Wimplicit-int -Wmisleading-indentation -Wpointer-arith -Wshorten-64-to-32 -Wwrite-strings -Wmissing-noreturn -Wno-constant-logical-operand -Wno-long-long -Wno-missing-field-initializers -Wno-overlength-strings -Wno-parentheses-equality -Wno-self-assign -Wno-tautological-compare -Wno-unused-parameter -Wno-unused-value -Wunused-variable -Wextra-tokens -pipe -Wall conftest.c -o conftest.i"
|
68
|
+
conftest.c:3:10: fatal error: 'sys/epoll.h' file not found
|
69
|
+
#include <sys/epoll.h>
|
70
|
+
^~~~~~~~~~~~~
|
71
|
+
1 error generated.
|
72
|
+
checked program was:
|
73
|
+
/* begin */
|
74
|
+
1: #include "ruby.h"
|
75
|
+
2:
|
76
|
+
3: #include <sys/epoll.h>
|
77
|
+
/* end */
|
78
|
+
|
79
|
+
--------------------
|
80
|
+
|
81
|
+
have_header: checking for sys/event.h... -------------------- yes
|
82
|
+
|
83
|
+
"clang -E -I/Users/samuel/.rubies/ruby-3.0.1/include/ruby-3.0.0/x86_64-darwin20 -I/Users/samuel/.rubies/ruby-3.0.1/include/ruby-3.0.0/ruby/backward -I/Users/samuel/.rubies/ruby-3.0.1/include/ruby-3.0.0 -I. -I/opt/local/include -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT -O3 -ggdb3 -Wall -Wextra -Wdeprecated-declarations -Wdivision-by-zero -Wimplicit-function-declaration -Wimplicit-int -Wmisleading-indentation -Wpointer-arith -Wshorten-64-to-32 -Wwrite-strings -Wmissing-noreturn -Wno-constant-logical-operand -Wno-long-long -Wno-missing-field-initializers -Wno-overlength-strings -Wno-parentheses-equality -Wno-self-assign -Wno-tautological-compare -Wno-unused-parameter -Wno-unused-value -Wunused-variable -Wextra-tokens -pipe -Wall conftest.c -o conftest.i"
|
84
|
+
checked program was:
|
85
|
+
/* begin */
|
86
|
+
1: #include "ruby.h"
|
87
|
+
2:
|
88
|
+
3: #include <sys/event.h>
|
89
|
+
/* end */
|
90
|
+
|
91
|
+
--------------------
|
92
|
+
|
93
|
+
have_func: checking for rb_io_descriptor()... -------------------- no
|
94
|
+
|
95
|
+
"clang -fdeclspec -o conftest -I/Users/samuel/.rubies/ruby-3.0.1/include/ruby-3.0.0/x86_64-darwin20 -I/Users/samuel/.rubies/ruby-3.0.1/include/ruby-3.0.0/ruby/backward -I/Users/samuel/.rubies/ruby-3.0.1/include/ruby-3.0.0 -I. -I/opt/local/include -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT -O3 -ggdb3 -Wall -Wextra -Wdeprecated-declarations -Wdivision-by-zero -Wimplicit-function-declaration -Wimplicit-int -Wmisleading-indentation -Wpointer-arith -Wshorten-64-to-32 -Wwrite-strings -Wmissing-noreturn -Wno-constant-logical-operand -Wno-long-long -Wno-missing-field-initializers -Wno-overlength-strings -Wno-parentheses-equality -Wno-self-assign -Wno-tautological-compare -Wno-unused-parameter -Wno-unused-value -Wunused-variable -Wextra-tokens -pipe -Wall conftest.c -L. -L/Users/samuel/.rubies/ruby-3.0.1/lib -L/opt/local/lib -L. -fstack-protector-strong -L/opt/local/lib -lruby.3.0-static -framework Security -framework Foundation -lpthread -lgmp -ldl -lobjc "
|
96
|
+
conftest.c:14:57: error: use of undeclared identifier 'rb_io_descriptor'
|
97
|
+
int t(void) { void ((*volatile p)()); p = (void ((*)()))rb_io_descriptor; return !p; }
|
98
|
+
^
|
99
|
+
1 error generated.
|
100
|
+
checked program was:
|
101
|
+
/* begin */
|
102
|
+
1: #include "ruby.h"
|
103
|
+
2:
|
104
|
+
3: /*top*/
|
105
|
+
4: extern int t(void);
|
106
|
+
5: int main(int argc, char **argv)
|
107
|
+
6: {
|
108
|
+
7: if (argc > 1000000) {
|
109
|
+
8: int (* volatile tp)(void)=(int (*)(void))&t;
|
110
|
+
9: printf("%d", (*tp)());
|
111
|
+
10: }
|
112
|
+
11:
|
113
|
+
12: return !!argv[argc];
|
114
|
+
13: }
|
115
|
+
14: int t(void) { void ((*volatile p)()); p = (void ((*)()))rb_io_descriptor; return !p; }
|
116
|
+
/* end */
|
117
|
+
|
118
|
+
"clang -fdeclspec -o conftest -I/Users/samuel/.rubies/ruby-3.0.1/include/ruby-3.0.0/x86_64-darwin20 -I/Users/samuel/.rubies/ruby-3.0.1/include/ruby-3.0.0/ruby/backward -I/Users/samuel/.rubies/ruby-3.0.1/include/ruby-3.0.0 -I. -I/opt/local/include -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT -O3 -ggdb3 -Wall -Wextra -Wdeprecated-declarations -Wdivision-by-zero -Wimplicit-function-declaration -Wimplicit-int -Wmisleading-indentation -Wpointer-arith -Wshorten-64-to-32 -Wwrite-strings -Wmissing-noreturn -Wno-constant-logical-operand -Wno-long-long -Wno-missing-field-initializers -Wno-overlength-strings -Wno-parentheses-equality -Wno-self-assign -Wno-tautological-compare -Wno-unused-parameter -Wno-unused-value -Wunused-variable -Wextra-tokens -pipe -Wall conftest.c -L. -L/Users/samuel/.rubies/ruby-3.0.1/lib -L/opt/local/lib -L. -fstack-protector-strong -L/opt/local/lib -lruby.3.0-static -framework Security -framework Foundation -lpthread -lgmp -ldl -lobjc "
|
119
|
+
Undefined symbols for architecture x86_64:
|
120
|
+
"_rb_io_descriptor", referenced from:
|
121
|
+
_t in conftest-9dccb6.o
|
122
|
+
ld: symbol(s) not found for architecture x86_64
|
123
|
+
clang: error: linker command failed with exit code 1 (use -v to see invocation)
|
124
|
+
checked program was:
|
125
|
+
/* begin */
|
126
|
+
1: #include "ruby.h"
|
127
|
+
2:
|
128
|
+
3: /*top*/
|
129
|
+
4: extern int t(void);
|
130
|
+
5: int main(int argc, char **argv)
|
131
|
+
6: {
|
132
|
+
7: if (argc > 1000000) {
|
133
|
+
8: int (* volatile tp)(void)=(int (*)(void))&t;
|
134
|
+
9: printf("%d", (*tp)());
|
135
|
+
10: }
|
136
|
+
11:
|
137
|
+
12: return !!argv[argc];
|
138
|
+
13: }
|
139
|
+
14: extern void rb_io_descriptor();
|
140
|
+
15: int t(void) { rb_io_descriptor(); return 0; }
|
141
|
+
/* end */
|
142
|
+
|
143
|
+
--------------------
|
144
|
+
|
145
|
+
have_func: checking for &rb_process_status_wait()... -------------------- no
|
146
|
+
|
147
|
+
"clang -fdeclspec -o conftest -I/Users/samuel/.rubies/ruby-3.0.1/include/ruby-3.0.0/x86_64-darwin20 -I/Users/samuel/.rubies/ruby-3.0.1/include/ruby-3.0.0/ruby/backward -I/Users/samuel/.rubies/ruby-3.0.1/include/ruby-3.0.0 -I. -I/opt/local/include -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT -O3 -ggdb3 -Wall -Wextra -Wdeprecated-declarations -Wdivision-by-zero -Wimplicit-function-declaration -Wimplicit-int -Wmisleading-indentation -Wpointer-arith -Wshorten-64-to-32 -Wwrite-strings -Wmissing-noreturn -Wno-constant-logical-operand -Wno-long-long -Wno-missing-field-initializers -Wno-overlength-strings -Wno-parentheses-equality -Wno-self-assign -Wno-tautological-compare -Wno-unused-parameter -Wno-unused-value -Wunused-variable -Wextra-tokens -pipe -Wall conftest.c -L. -L/Users/samuel/.rubies/ruby-3.0.1/lib -L/opt/local/lib -L. -fstack-protector-strong -L/opt/local/lib -lruby.3.0-static -framework Security -framework Foundation -lpthread -lgmp -ldl -lobjc "
|
148
|
+
conftest.c:14:76: error: use of undeclared identifier 'rb_process_status_wait'
|
149
|
+
int t(void) { const volatile void *volatile p; p = (const volatile void *)&rb_process_status_wait; return !p; }
|
150
|
+
^
|
151
|
+
1 error generated.
|
152
|
+
checked program was:
|
153
|
+
/* begin */
|
154
|
+
1: #include "ruby.h"
|
155
|
+
2:
|
156
|
+
3: /*top*/
|
157
|
+
4: extern int t(void);
|
158
|
+
5: int main(int argc, char **argv)
|
159
|
+
6: {
|
160
|
+
7: if (argc > 1000000) {
|
161
|
+
8: int (* volatile tp)(void)=(int (*)(void))&t;
|
162
|
+
9: printf("%d", (*tp)());
|
163
|
+
10: }
|
164
|
+
11:
|
165
|
+
12: return !!argv[argc];
|
166
|
+
13: }
|
167
|
+
14: int t(void) { const volatile void *volatile p; p = (const volatile void *)&rb_process_status_wait; return !p; }
|
168
|
+
/* end */
|
169
|
+
|
170
|
+
--------------------
|
171
|
+
|
172
|
+
have_header: checking for ruby/io/buffer.h... -------------------- no
|
173
|
+
|
174
|
+
"clang -E -I/Users/samuel/.rubies/ruby-3.0.1/include/ruby-3.0.0/x86_64-darwin20 -I/Users/samuel/.rubies/ruby-3.0.1/include/ruby-3.0.0/ruby/backward -I/Users/samuel/.rubies/ruby-3.0.1/include/ruby-3.0.0 -I. -I/opt/local/include -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT -O3 -ggdb3 -Wall -Wextra -Wdeprecated-declarations -Wdivision-by-zero -Wimplicit-function-declaration -Wimplicit-int -Wmisleading-indentation -Wpointer-arith -Wshorten-64-to-32 -Wwrite-strings -Wmissing-noreturn -Wno-constant-logical-operand -Wno-long-long -Wno-missing-field-initializers -Wno-overlength-strings -Wno-parentheses-equality -Wno-self-assign -Wno-tautological-compare -Wno-unused-parameter -Wno-unused-value -Wunused-variable -Wextra-tokens -pipe -Wall conftest.c -o conftest.i"
|
175
|
+
conftest.c:3:10: fatal error: 'ruby/io/buffer.h' file not found
|
176
|
+
#include <ruby/io/buffer.h>
|
177
|
+
^~~~~~~~~~~~~~~~~~
|
178
|
+
1 error generated.
|
179
|
+
checked program was:
|
180
|
+
/* begin */
|
181
|
+
1: #include "ruby.h"
|
182
|
+
2:
|
183
|
+
3: #include <ruby/io/buffer.h>
|
184
|
+
/* end */
|
185
|
+
|
186
|
+
--------------------
|
187
|
+
|
188
|
+
extconf.h is:
|
189
|
+
/* begin */
|
190
|
+
1: #ifndef EXTCONF_H
|
191
|
+
2: #define EXTCONF_H
|
192
|
+
3: #define HAVE_SYS_EVENT_H 1
|
193
|
+
4: #endif
|
194
|
+
/* end */
|
195
|
+
|
data/lib/event/backend/select.rb
CHANGED
@@ -26,6 +26,8 @@ module Event
|
|
26
26
|
|
27
27
|
@readable = {}
|
28
28
|
@writable = {}
|
29
|
+
|
30
|
+
@ready = []
|
29
31
|
end
|
30
32
|
|
31
33
|
def close
|
@@ -34,6 +36,24 @@ module Event
|
|
34
36
|
@writable = nil
|
35
37
|
end
|
36
38
|
|
39
|
+
def defer
|
40
|
+
fiber = Fiber.current
|
41
|
+
@ready.push(fiber)
|
42
|
+
@loop.transfer
|
43
|
+
ensure
|
44
|
+
# Linear scan :(
|
45
|
+
@ready.delete(fiber)
|
46
|
+
end
|
47
|
+
|
48
|
+
def transfer(fiber)
|
49
|
+
@ready.push(Fiber.current)
|
50
|
+
fiber.transfer
|
51
|
+
end
|
52
|
+
|
53
|
+
def ready?
|
54
|
+
@ready.any?
|
55
|
+
end
|
56
|
+
|
37
57
|
def io_wait(fiber, io, events)
|
38
58
|
remove_readable = remove_writable = false
|
39
59
|
|
@@ -53,7 +73,76 @@ module Event
|
|
53
73
|
@writable.delete(io) if remove_writable
|
54
74
|
end
|
55
75
|
|
76
|
+
if IO.const_defined?(:Buffer)
|
77
|
+
def io_read(fiber, io, buffer, length)
|
78
|
+
offset = 0
|
79
|
+
|
80
|
+
while length > 0
|
81
|
+
# The maximum size we can read:
|
82
|
+
maximum_size = buffer.size - offset
|
83
|
+
|
84
|
+
case result = io.read_nonblock(maximum_size, exception: false)
|
85
|
+
when :wait_readable
|
86
|
+
self.io_wait(fiber, io, READABLE)
|
87
|
+
when :wait_writable
|
88
|
+
self.io_wait(fiber, io, WRITABLE)
|
89
|
+
else
|
90
|
+
break if result.empty?
|
91
|
+
|
92
|
+
buffer.copy(result, offset)
|
93
|
+
|
94
|
+
offset += result.bytesize
|
95
|
+
length -= result.bytesize
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
return offset
|
100
|
+
end
|
101
|
+
|
102
|
+
def io_write(fiber, io, buffer, length)
|
103
|
+
offset = 0
|
104
|
+
|
105
|
+
while length > 0
|
106
|
+
# From offset until the end:
|
107
|
+
chunk = buffer.to_str(offset, length)
|
108
|
+
case result = io.write_nonblock(chunk, exception: false)
|
109
|
+
when :wait_readable
|
110
|
+
self.io_wait(fiber, io, READABLE)
|
111
|
+
when :wait_writable
|
112
|
+
self.io_wait(fiber, io, WRITABLE)
|
113
|
+
else
|
114
|
+
offset += result
|
115
|
+
length -= result
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
return offset
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
def process_wait(fiber, pid, flags)
|
124
|
+
r, w = IO.pipe
|
125
|
+
|
126
|
+
thread = Thread.new do
|
127
|
+
Process::Status.wait(pid, flags)
|
128
|
+
ensure
|
129
|
+
w.close
|
130
|
+
end
|
131
|
+
|
132
|
+
self.io_wait(fiber, r, READABLE)
|
133
|
+
|
134
|
+
return thread.value
|
135
|
+
ensure
|
136
|
+
r.close
|
137
|
+
w.close
|
138
|
+
thread&.kill
|
139
|
+
end
|
140
|
+
|
56
141
|
def select(duration = nil)
|
142
|
+
while @ready.any?
|
143
|
+
@ready.pop.transfer
|
144
|
+
end
|
145
|
+
|
57
146
|
readable, writable, _ = ::IO.select(@readable.keys, @writable.keys, nil, duration)
|
58
147
|
|
59
148
|
ready = Hash.new(0)
|
@@ -69,7 +158,7 @@ module Event
|
|
69
158
|
end
|
70
159
|
|
71
160
|
ready.each do |fiber, events|
|
72
|
-
fiber.transfer(events)
|
161
|
+
fiber.transfer(events) if fiber.alive?
|
73
162
|
end
|
74
163
|
end
|
75
164
|
end
|
data/lib/event/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: event
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Samuel Williams
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-07-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bake
|
@@ -73,16 +73,25 @@ extensions:
|
|
73
73
|
- ext/event/extconf.rb
|
74
74
|
extra_rdoc_files: []
|
75
75
|
files:
|
76
|
+
- ext/event/Makefile
|
77
|
+
- ext/event/backend.o
|
78
|
+
- ext/event/backend/backend.c
|
76
79
|
- ext/event/backend/backend.h
|
77
80
|
- ext/event/backend/epoll.c
|
78
81
|
- ext/event/backend/epoll.h
|
79
82
|
- ext/event/backend/kqueue.c
|
80
83
|
- ext/event/backend/kqueue.h
|
84
|
+
- ext/event/backend/pidfd.c
|
81
85
|
- ext/event/backend/uring.c
|
82
86
|
- ext/event/backend/uring.h
|
87
|
+
- ext/event/event.bundle
|
83
88
|
- ext/event/event.c
|
84
89
|
- ext/event/event.h
|
90
|
+
- ext/event/event.o
|
91
|
+
- ext/event/extconf.h
|
85
92
|
- ext/event/extconf.rb
|
93
|
+
- ext/event/kqueue.o
|
94
|
+
- ext/event/mkmf.log
|
86
95
|
- lib/event.rb
|
87
96
|
- lib/event/backend.rb
|
88
97
|
- lib/event/backend/select.rb
|
@@ -108,7 +117,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
108
117
|
- !ruby/object:Gem::Version
|
109
118
|
version: '0'
|
110
119
|
requirements: []
|
111
|
-
rubygems_version: 3.
|
120
|
+
rubygems_version: 3.2.15
|
112
121
|
signing_key:
|
113
122
|
specification_version: 4
|
114
123
|
summary: An event loop.
|