event 0.7.0 → 0.9.0
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/ext/event/event.c +12 -12
- data/ext/event/event.h +3 -3
- data/ext/event/extconf.rb +8 -5
- data/ext/event/{backend → selector}/epoll.c +114 -90
- data/ext/event/{backend → selector}/epoll.h +2 -2
- data/ext/event/{backend → selector}/kqueue.c +115 -94
- data/ext/event/{backend → selector}/kqueue.h +2 -2
- data/ext/event/{backend → selector}/pidfd.c +0 -0
- data/ext/event/selector/selector.c +285 -0
- data/ext/event/selector/selector.h +123 -0
- data/ext/event/{backend → selector}/uring.c +144 -133
- data/ext/event/{backend → selector}/uring.h +3 -3
- data/lib/event.rb +1 -1
- data/lib/event/debug.rb +126 -0
- data/lib/event/selector.rb +25 -2
- data/lib/event/{backend → selector}/select.rb +59 -11
- data/lib/event/version.rb +1 -1
- metadata +14 -22
- data/ext/event/Makefile +0 -267
- data/ext/event/backend.o +0 -0
- data/ext/event/backend/backend.c +0 -178
- data/ext/event/backend/backend.h +0 -112
- data/ext/event/event.bundle +0 -0
- data/ext/event/event.o +0 -0
- data/ext/event/extconf.h +0 -4
- data/ext/event/kqueue.o +0 -0
- data/ext/event/mkmf.log +0 -195
- data/lib/event/backend.rb +0 -49
- data/lib/event/debug/selector.rb +0 -108
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3d1a02b3163aca45dcdb7ac4f3589e18894c3e753262d7934ea0f473c88e2a38
|
4
|
+
data.tar.gz: fac7fd3d48e616e1c03ca9cb6af19b8457c4dadb452261bb1f4b628d70297bcb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 54c8d94a288dc450decd427c2bd7af850b635133b90ca25ee15f4f934c3e9b78cd8465402d1fabb9c4bae8ae3b7fef8c1849567e23303601a2bca4dfefc9acf3
|
7
|
+
data.tar.gz: 757e2b00714ace1767d732ab37c93372bd44d14da4911f46190b8ba0efcb1ba249743509fc3c68e957c4b24804ddd35a844257b81e279de0f3fd487d1058015e
|
data/ext/event/event.c
CHANGED
@@ -19,31 +19,31 @@
|
|
19
19
|
// THE SOFTWARE.
|
20
20
|
|
21
21
|
#include "event.h"
|
22
|
-
#include "
|
22
|
+
#include "selector/selector.h"
|
23
23
|
|
24
24
|
VALUE Event = Qnil;
|
25
|
-
VALUE
|
25
|
+
VALUE Event_Selector = Qnil;
|
26
26
|
|
27
27
|
void Init_event()
|
28
28
|
{
|
29
|
-
|
29
|
+
#ifdef HAVE_RB_EXT_RACTOR_SAFE
|
30
30
|
rb_ext_ractor_safe(true);
|
31
|
-
|
31
|
+
#endif
|
32
32
|
|
33
33
|
Event = rb_define_module("Event");
|
34
|
-
|
34
|
+
Event_Selector = rb_define_module_under(Event, "Selector");
|
35
35
|
|
36
|
-
|
36
|
+
Init_Event_Selector(Event_Selector);
|
37
37
|
|
38
|
-
#ifdef
|
39
|
-
|
38
|
+
#ifdef EVENT_SELECTOR_URING
|
39
|
+
Init_Event_Selector_URing(Event_Selector);
|
40
40
|
#endif
|
41
41
|
|
42
|
-
#ifdef
|
43
|
-
|
42
|
+
#ifdef EVENT_SELECTOR_EPOLL
|
43
|
+
Init_Event_Selector_EPoll(Event_Selector);
|
44
44
|
#endif
|
45
45
|
|
46
|
-
#ifdef
|
47
|
-
|
46
|
+
#ifdef EVENT_SELECTOR_KQUEUE
|
47
|
+
Init_Event_Selector_KQueue(Event_Selector);
|
48
48
|
#endif
|
49
49
|
}
|
data/ext/event/event.h
CHANGED
@@ -27,13 +27,13 @@
|
|
27
27
|
void Init_event();
|
28
28
|
|
29
29
|
#ifdef HAVE_LIBURING_H
|
30
|
-
#include "
|
30
|
+
#include "selector/uring.h"
|
31
31
|
#endif
|
32
32
|
|
33
33
|
#ifdef HAVE_SYS_EPOLL_H
|
34
|
-
#include "
|
34
|
+
#include "selector/epoll.h"
|
35
35
|
#endif
|
36
36
|
|
37
37
|
#ifdef HAVE_SYS_EVENT_H
|
38
|
-
#include "
|
38
|
+
#include "selector/kqueue.h"
|
39
39
|
#endif
|
data/ext/event/extconf.rb
CHANGED
@@ -30,25 +30,28 @@ dir_config(extension_name)
|
|
30
30
|
|
31
31
|
$CFLAGS << " -Wall"
|
32
32
|
|
33
|
-
$srcs = ["event.c", "
|
34
|
-
$VPATH << "$(srcdir)/
|
33
|
+
$srcs = ["event.c", "selector/selector.c"]
|
34
|
+
$VPATH << "$(srcdir)/selector"
|
35
35
|
|
36
|
+
have_func('rb_ext_ractor_safe')
|
36
37
|
have_func('&rb_fiber_transfer')
|
37
38
|
|
38
39
|
if have_library('uring') and have_header('liburing.h')
|
39
|
-
$srcs << "
|
40
|
+
$srcs << "selector/uring.c"
|
40
41
|
end
|
41
42
|
|
42
43
|
if have_header('sys/epoll.h')
|
43
|
-
$srcs << "
|
44
|
+
$srcs << "selector/epoll.c"
|
44
45
|
end
|
45
46
|
|
46
47
|
if have_header('sys/event.h')
|
47
|
-
$srcs << "
|
48
|
+
$srcs << "selector/kqueue.c"
|
48
49
|
end
|
49
50
|
|
50
51
|
have_func("rb_io_descriptor")
|
51
52
|
have_func("&rb_process_status_wait")
|
53
|
+
have_func('rb_fiber_current')
|
54
|
+
have_func("&rb_fiber_raise")
|
52
55
|
|
53
56
|
have_header('ruby/io/buffer.h')
|
54
57
|
|
@@ -19,7 +19,7 @@
|
|
19
19
|
// THE SOFTWARE.
|
20
20
|
|
21
21
|
#include "kqueue.h"
|
22
|
-
#include "
|
22
|
+
#include "selector.h"
|
23
23
|
|
24
24
|
#include <sys/epoll.h>
|
25
25
|
#include <time.h>
|
@@ -27,69 +27,69 @@
|
|
27
27
|
|
28
28
|
#include "pidfd.c"
|
29
29
|
|
30
|
-
static VALUE
|
30
|
+
static VALUE Event_Selector_EPoll = Qnil;
|
31
31
|
|
32
32
|
enum {EPOLL_MAX_EVENTS = 64};
|
33
33
|
|
34
|
-
struct
|
35
|
-
struct
|
34
|
+
struct Event_Selector_EPoll {
|
35
|
+
struct Event_Selector backend;
|
36
36
|
int descriptor;
|
37
37
|
};
|
38
38
|
|
39
|
-
void
|
39
|
+
void Event_Selector_EPoll_Type_mark(void *_data)
|
40
40
|
{
|
41
|
-
struct
|
42
|
-
|
41
|
+
struct Event_Selector_EPoll *data = _data;
|
42
|
+
Event_Selector_mark(&data->backend);
|
43
43
|
}
|
44
44
|
|
45
45
|
static
|
46
|
-
void close_internal(struct
|
46
|
+
void close_internal(struct Event_Selector_EPoll *data) {
|
47
47
|
if (data->descriptor >= 0) {
|
48
48
|
close(data->descriptor);
|
49
49
|
data->descriptor = -1;
|
50
50
|
}
|
51
51
|
}
|
52
52
|
|
53
|
-
void
|
53
|
+
void Event_Selector_EPoll_Type_free(void *_data)
|
54
54
|
{
|
55
|
-
struct
|
55
|
+
struct Event_Selector_EPoll *data = _data;
|
56
56
|
|
57
57
|
close_internal(data);
|
58
58
|
|
59
59
|
free(data);
|
60
60
|
}
|
61
61
|
|
62
|
-
size_t
|
62
|
+
size_t Event_Selector_EPoll_Type_size(const void *data)
|
63
63
|
{
|
64
|
-
return sizeof(struct
|
64
|
+
return sizeof(struct Event_Selector_EPoll);
|
65
65
|
}
|
66
66
|
|
67
|
-
static const rb_data_type_t
|
67
|
+
static const rb_data_type_t Event_Selector_EPoll_Type = {
|
68
68
|
.wrap_struct_name = "Event::Backend::EPoll",
|
69
69
|
.function = {
|
70
|
-
.dmark =
|
71
|
-
.dfree =
|
72
|
-
.dsize =
|
70
|
+
.dmark = Event_Selector_EPoll_Type_mark,
|
71
|
+
.dfree = Event_Selector_EPoll_Type_free,
|
72
|
+
.dsize = Event_Selector_EPoll_Type_size,
|
73
73
|
},
|
74
74
|
.data = NULL,
|
75
75
|
.flags = RUBY_TYPED_FREE_IMMEDIATELY,
|
76
76
|
};
|
77
77
|
|
78
|
-
VALUE
|
79
|
-
struct
|
80
|
-
VALUE instance = TypedData_Make_Struct(self, struct
|
78
|
+
VALUE Event_Selector_EPoll_allocate(VALUE self) {
|
79
|
+
struct Event_Selector_EPoll *data = NULL;
|
80
|
+
VALUE instance = TypedData_Make_Struct(self, struct Event_Selector_EPoll, &Event_Selector_EPoll_Type, data);
|
81
81
|
|
82
|
-
|
82
|
+
Event_Selector_initialize(&data->backend, Qnil);
|
83
83
|
data->descriptor = -1;
|
84
84
|
|
85
85
|
return instance;
|
86
86
|
}
|
87
87
|
|
88
|
-
VALUE
|
89
|
-
struct
|
90
|
-
TypedData_Get_Struct(self, struct
|
88
|
+
VALUE Event_Selector_EPoll_initialize(VALUE self, VALUE loop) {
|
89
|
+
struct Event_Selector_EPoll *data = NULL;
|
90
|
+
TypedData_Get_Struct(self, struct Event_Selector_EPoll, &Event_Selector_EPoll_Type, data);
|
91
91
|
|
92
|
-
|
92
|
+
Event_Selector_initialize(&data->backend, loop);
|
93
93
|
int result = epoll_create1(EPOLL_CLOEXEC);
|
94
94
|
|
95
95
|
if (result == -1) {
|
@@ -103,44 +103,62 @@ VALUE Event_Backend_EPoll_initialize(VALUE self, VALUE loop) {
|
|
103
103
|
return self;
|
104
104
|
}
|
105
105
|
|
106
|
-
VALUE
|
107
|
-
struct
|
108
|
-
TypedData_Get_Struct(self, struct
|
106
|
+
VALUE Event_Selector_EPoll_close(VALUE self) {
|
107
|
+
struct Event_Selector_EPoll *data = NULL;
|
108
|
+
TypedData_Get_Struct(self, struct Event_Selector_EPoll, &Event_Selector_EPoll_Type, data);
|
109
109
|
|
110
110
|
close_internal(data);
|
111
111
|
|
112
112
|
return Qnil;
|
113
113
|
}
|
114
114
|
|
115
|
-
VALUE
|
115
|
+
VALUE Event_Selector_EPoll_resume(int argc, VALUE *argv, VALUE self)
|
116
116
|
{
|
117
|
-
struct
|
118
|
-
TypedData_Get_Struct(self, struct
|
117
|
+
struct Event_Selector_EPoll *data = NULL;
|
118
|
+
TypedData_Get_Struct(self, struct Event_Selector_EPoll, &Event_Selector_EPoll_Type, data);
|
119
119
|
|
120
|
-
|
120
|
+
Event_Selector_resume(&data->backend, argc, argv);
|
121
121
|
|
122
122
|
return Qnil;
|
123
123
|
}
|
124
124
|
|
125
|
-
VALUE
|
125
|
+
VALUE Event_Selector_EPoll_yield(VALUE self)
|
126
126
|
{
|
127
|
-
struct
|
128
|
-
TypedData_Get_Struct(self, struct
|
127
|
+
struct Event_Selector_EPoll *data = NULL;
|
128
|
+
TypedData_Get_Struct(self, struct Event_Selector_EPoll, &Event_Selector_EPoll_Type, data);
|
129
129
|
|
130
|
-
|
130
|
+
Event_Selector_yield(&data->backend);
|
131
131
|
|
132
132
|
return Qnil;
|
133
133
|
}
|
134
134
|
|
135
|
-
VALUE
|
136
|
-
|
137
|
-
|
135
|
+
VALUE Event_Selector_EPoll_push(VALUE self, VALUE fiber)
|
136
|
+
{
|
137
|
+
struct Event_Selector_EPoll *data = NULL;
|
138
|
+
TypedData_Get_Struct(self, struct Event_Selector_EPoll, &Event_Selector_EPoll_Type, data);
|
139
|
+
|
140
|
+
Event_Selector_queue_push(&data->backend, fiber);
|
141
|
+
|
142
|
+
return Qnil;
|
143
|
+
}
|
144
|
+
|
145
|
+
VALUE Event_Selector_EPoll_raise(int argc, VALUE *argv, VALUE self)
|
146
|
+
{
|
147
|
+
struct Event_Selector_EPoll *data = NULL;
|
148
|
+
TypedData_Get_Struct(self, struct Event_Selector_EPoll, &Event_Selector_EPoll_Type, data);
|
149
|
+
|
150
|
+
return Event_Selector_wait_and_raise(&data->backend, argc, argv);
|
151
|
+
}
|
152
|
+
|
153
|
+
VALUE Event_Selector_EPoll_ready_p(VALUE self) {
|
154
|
+
struct Event_Selector_EPoll *data = NULL;
|
155
|
+
TypedData_Get_Struct(self, struct Event_Selector_EPoll, &Event_Selector_EPoll_Type, data);
|
138
156
|
|
139
157
|
return data->backend.ready ? Qtrue : Qfalse;
|
140
158
|
}
|
141
159
|
|
142
160
|
struct process_wait_arguments {
|
143
|
-
struct
|
161
|
+
struct Event_Selector_EPoll *data;
|
144
162
|
pid_t pid;
|
145
163
|
int flags;
|
146
164
|
int descriptor;
|
@@ -150,9 +168,9 @@ static
|
|
150
168
|
VALUE process_wait_transfer(VALUE _arguments) {
|
151
169
|
struct process_wait_arguments *arguments = (struct process_wait_arguments *)_arguments;
|
152
170
|
|
153
|
-
|
171
|
+
Event_Selector_fiber_transfer(arguments->data->backend.loop, 0, NULL);
|
154
172
|
|
155
|
-
return
|
173
|
+
return Event_Selector_process_status_wait(arguments->pid);
|
156
174
|
}
|
157
175
|
|
158
176
|
static
|
@@ -166,9 +184,9 @@ VALUE process_wait_ensure(VALUE _arguments) {
|
|
166
184
|
return Qnil;
|
167
185
|
}
|
168
186
|
|
169
|
-
VALUE
|
170
|
-
struct
|
171
|
-
TypedData_Get_Struct(self, struct
|
187
|
+
VALUE Event_Selector_EPoll_process_wait(VALUE self, VALUE fiber, VALUE pid, VALUE flags) {
|
188
|
+
struct Event_Selector_EPoll *data = NULL;
|
189
|
+
TypedData_Get_Struct(self, struct Event_Selector_EPoll, &Event_Selector_EPoll_Type, data);
|
172
190
|
|
173
191
|
struct process_wait_arguments process_wait_arguments = {
|
174
192
|
.data = data,
|
@@ -197,9 +215,9 @@ static inline
|
|
197
215
|
uint32_t epoll_flags_from_events(int events) {
|
198
216
|
uint32_t flags = 0;
|
199
217
|
|
200
|
-
if (events &
|
201
|
-
if (events &
|
202
|
-
if (events &
|
218
|
+
if (events & EVENT_READABLE) flags |= EPOLLIN;
|
219
|
+
if (events & EVENT_PRIORITY) flags |= EPOLLPRI;
|
220
|
+
if (events & EVENT_WRITABLE) flags |= EPOLLOUT;
|
203
221
|
|
204
222
|
flags |= EPOLLRDHUP;
|
205
223
|
flags |= EPOLLONESHOT;
|
@@ -211,15 +229,15 @@ static inline
|
|
211
229
|
int events_from_epoll_flags(uint32_t flags) {
|
212
230
|
int events = 0;
|
213
231
|
|
214
|
-
if (flags & EPOLLIN) events |=
|
215
|
-
if (flags & EPOLLPRI) events |=
|
216
|
-
if (flags & EPOLLOUT) events |=
|
232
|
+
if (flags & EPOLLIN) events |= EVENT_READABLE;
|
233
|
+
if (flags & EPOLLPRI) events |= EVENT_PRIORITY;
|
234
|
+
if (flags & EPOLLOUT) events |= EVENT_WRITABLE;
|
217
235
|
|
218
236
|
return events;
|
219
237
|
}
|
220
238
|
|
221
239
|
struct io_wait_arguments {
|
222
|
-
struct
|
240
|
+
struct Event_Selector_EPoll *data;
|
223
241
|
int descriptor;
|
224
242
|
int duplicate;
|
225
243
|
};
|
@@ -243,18 +261,18 @@ static
|
|
243
261
|
VALUE io_wait_transfer(VALUE _arguments) {
|
244
262
|
struct io_wait_arguments *arguments = (struct io_wait_arguments *)_arguments;
|
245
263
|
|
246
|
-
VALUE result =
|
264
|
+
VALUE result = Event_Selector_fiber_transfer(arguments->data->backend.loop, 0, NULL);
|
247
265
|
|
248
266
|
return INT2NUM(events_from_epoll_flags(NUM2INT(result)));
|
249
267
|
};
|
250
268
|
|
251
|
-
VALUE
|
252
|
-
struct
|
253
|
-
TypedData_Get_Struct(self, struct
|
269
|
+
VALUE Event_Selector_EPoll_io_wait(VALUE self, VALUE fiber, VALUE io, VALUE events) {
|
270
|
+
struct Event_Selector_EPoll *data = NULL;
|
271
|
+
TypedData_Get_Struct(self, struct Event_Selector_EPoll, &Event_Selector_EPoll_Type, data);
|
254
272
|
|
255
273
|
struct epoll_event event = {0};
|
256
274
|
|
257
|
-
int descriptor =
|
275
|
+
int descriptor = Event_Selector_io_descriptor(io);
|
258
276
|
int duplicate = -1;
|
259
277
|
|
260
278
|
event.events = epoll_flags_from_events(NUM2INT(events));
|
@@ -326,9 +344,9 @@ VALUE io_read_loop(VALUE _arguments) {
|
|
326
344
|
offset += result;
|
327
345
|
length -= result;
|
328
346
|
} else if (errno == EAGAIN || errno == EWOULDBLOCK) {
|
329
|
-
|
347
|
+
Event_Selector_EPoll_io_wait(arguments->self, arguments->fiber, arguments->io, RB_INT2NUM(EVENT_READABLE));
|
330
348
|
} else {
|
331
|
-
rb_sys_fail("
|
349
|
+
rb_sys_fail("Event_Selector_EPoll_io_read");
|
332
350
|
}
|
333
351
|
}
|
334
352
|
|
@@ -339,13 +357,13 @@ static
|
|
339
357
|
VALUE io_read_ensure(VALUE _arguments) {
|
340
358
|
struct io_read_arguments *arguments = (struct io_read_arguments *)_arguments;
|
341
359
|
|
342
|
-
|
360
|
+
Event_Selector_nonblock_restore(arguments->descriptor, arguments->flags);
|
343
361
|
|
344
362
|
return Qnil;
|
345
363
|
}
|
346
364
|
|
347
|
-
VALUE
|
348
|
-
int descriptor =
|
365
|
+
VALUE Event_Selector_EPoll_io_read(VALUE self, VALUE fiber, VALUE io, VALUE buffer, VALUE _length) {
|
366
|
+
int descriptor = Event_Selector_io_descriptor(io);
|
349
367
|
|
350
368
|
size_t length = NUM2SIZET(_length);
|
351
369
|
|
@@ -354,7 +372,7 @@ VALUE Event_Backend_EPoll_io_read(VALUE self, VALUE fiber, VALUE io, VALUE buffe
|
|
354
372
|
.fiber = fiber,
|
355
373
|
.io = io,
|
356
374
|
|
357
|
-
.flags =
|
375
|
+
.flags = Event_Selector_nonblock_set(descriptor),
|
358
376
|
.descriptor = descriptor,
|
359
377
|
.buffer = buffer,
|
360
378
|
.length = length,
|
@@ -398,9 +416,9 @@ VALUE io_write_loop(VALUE _arguments) {
|
|
398
416
|
offset += result;
|
399
417
|
length -= result;
|
400
418
|
} else if (errno == EAGAIN || errno == EWOULDBLOCK) {
|
401
|
-
|
419
|
+
Event_Selector_EPoll_io_wait(arguments->self, arguments->fiber, arguments->io, RB_INT2NUM(EVENT_WRITABLE));
|
402
420
|
} else {
|
403
|
-
rb_sys_fail("
|
421
|
+
rb_sys_fail("Event_Selector_EPoll_io_write");
|
404
422
|
}
|
405
423
|
}
|
406
424
|
|
@@ -411,13 +429,13 @@ static
|
|
411
429
|
VALUE io_write_ensure(VALUE _arguments) {
|
412
430
|
struct io_write_arguments *arguments = (struct io_write_arguments *)_arguments;
|
413
431
|
|
414
|
-
|
432
|
+
Event_Selector_nonblock_restore(arguments->descriptor, arguments->flags);
|
415
433
|
|
416
434
|
return Qnil;
|
417
435
|
};
|
418
436
|
|
419
|
-
VALUE
|
420
|
-
int descriptor =
|
437
|
+
VALUE Event_Selector_EPoll_io_write(VALUE self, VALUE fiber, VALUE io, VALUE buffer, VALUE _length) {
|
438
|
+
int descriptor = Event_Selector_io_descriptor(io);
|
421
439
|
|
422
440
|
size_t length = NUM2SIZET(_length);
|
423
441
|
|
@@ -426,7 +444,7 @@ VALUE Event_Backend_EPoll_io_write(VALUE self, VALUE fiber, VALUE io, VALUE buff
|
|
426
444
|
.fiber = fiber,
|
427
445
|
.io = io,
|
428
446
|
|
429
|
-
.flags =
|
447
|
+
.flags = Event_Selector_nonblock_set(descriptor),
|
430
448
|
.descriptor = descriptor,
|
431
449
|
.buffer = buffer,
|
432
450
|
.length = length,
|
@@ -457,7 +475,7 @@ int make_timeout(VALUE duration) {
|
|
457
475
|
}
|
458
476
|
|
459
477
|
struct select_arguments {
|
460
|
-
struct
|
478
|
+
struct Event_Selector_EPoll *data;
|
461
479
|
|
462
480
|
int count;
|
463
481
|
struct epoll_event events[EPOLL_MAX_EVENTS];
|
@@ -492,11 +510,11 @@ void select_internal_with_gvl(struct select_arguments *arguments) {
|
|
492
510
|
}
|
493
511
|
}
|
494
512
|
|
495
|
-
VALUE
|
496
|
-
struct
|
497
|
-
TypedData_Get_Struct(self, struct
|
513
|
+
VALUE Event_Selector_EPoll_select(VALUE self, VALUE duration) {
|
514
|
+
struct Event_Selector_EPoll *data = NULL;
|
515
|
+
TypedData_Get_Struct(self, struct Event_Selector_EPoll, &Event_Selector_EPoll_Type, data);
|
498
516
|
|
499
|
-
|
517
|
+
int ready = Event_Selector_queue_flush(&data->backend);
|
500
518
|
|
501
519
|
struct select_arguments arguments = {
|
502
520
|
.data = data,
|
@@ -504,11 +522,12 @@ VALUE Event_Backend_EPoll_select(VALUE self, VALUE duration) {
|
|
504
522
|
};
|
505
523
|
|
506
524
|
select_internal_with_gvl(&arguments);
|
507
|
-
|
508
|
-
|
525
|
+
|
526
|
+
// If the ready list was empty and no events were processed:
|
527
|
+
if (!ready && arguments.count == 0) {
|
509
528
|
arguments.timeout = make_timeout(duration);
|
510
529
|
|
511
|
-
if (
|
530
|
+
if (arguments.timeout != 0) {
|
512
531
|
select_internal_without_gvl(&arguments);
|
513
532
|
}
|
514
533
|
}
|
@@ -519,29 +538,34 @@ VALUE Event_Backend_EPoll_select(VALUE self, VALUE duration) {
|
|
519
538
|
|
520
539
|
// fprintf(stderr, "-> fiber=%p descriptor=%d\n", (void*)fiber, events[i].data.fd);
|
521
540
|
|
522
|
-
|
541
|
+
Event_Selector_fiber_transfer(fiber, 1, &result);
|
523
542
|
}
|
524
543
|
|
525
544
|
return INT2NUM(arguments.count);
|
526
545
|
}
|
527
546
|
|
528
|
-
void
|
529
|
-
|
547
|
+
void Init_Event_Selector_EPoll(VALUE Event_Selector) {
|
548
|
+
Event_Selector_EPoll = rb_define_class_under(Event_Selector, "EPoll", rb_cObject);
|
549
|
+
|
550
|
+
rb_define_alloc_func(Event_Selector_EPoll, Event_Selector_EPoll_allocate);
|
551
|
+
rb_define_method(Event_Selector_EPoll, "initialize", Event_Selector_EPoll_initialize, 1);
|
552
|
+
|
553
|
+
rb_define_method(Event_Selector_EPoll, "resume", Event_Selector_EPoll_resume, -1);
|
554
|
+
rb_define_method(Event_Selector_EPoll, "yield", Event_Selector_EPoll_yield, 0);
|
555
|
+
rb_define_method(Event_Selector_EPoll, "push", Event_Selector_EPoll_push, 1);
|
556
|
+
rb_define_method(Event_Selector_EPoll, "raise", Event_Selector_EPoll_raise, -1);
|
557
|
+
|
558
|
+
rb_define_method(Event_Selector_EPoll, "ready?", Event_Selector_EPoll_ready_p, 0);
|
530
559
|
|
531
|
-
|
532
|
-
rb_define_method(
|
533
|
-
rb_define_method(Event_Backend_EPoll, "transfer", Event_Backend_EPoll_transfer, 1);
|
534
|
-
rb_define_method(Event_Backend_EPoll, "defer", Event_Backend_EPoll_defer, 0);
|
535
|
-
rb_define_method(Event_Backend_EPoll, "ready?", Event_Backend_EPoll_ready_p, 0);
|
536
|
-
rb_define_method(Event_Backend_EPoll, "select", Event_Backend_EPoll_select, 1);
|
537
|
-
rb_define_method(Event_Backend_EPoll, "close", Event_Backend_EPoll_close, 0);
|
560
|
+
rb_define_method(Event_Selector_EPoll, "select", Event_Selector_EPoll_select, 1);
|
561
|
+
rb_define_method(Event_Selector_EPoll, "close", Event_Selector_EPoll_close, 0);
|
538
562
|
|
539
|
-
rb_define_method(
|
563
|
+
rb_define_method(Event_Selector_EPoll, "io_wait", Event_Selector_EPoll_io_wait, 3);
|
540
564
|
|
541
565
|
#ifdef HAVE_RUBY_IO_BUFFER_H
|
542
|
-
rb_define_method(
|
543
|
-
rb_define_method(
|
566
|
+
rb_define_method(Event_Selector_EPoll, "io_read", Event_Selector_EPoll_io_read, 4);
|
567
|
+
rb_define_method(Event_Selector_EPoll, "io_write", Event_Selector_EPoll_io_write, 4);
|
544
568
|
#endif
|
545
569
|
|
546
|
-
rb_define_method(
|
570
|
+
rb_define_method(Event_Selector_EPoll, "process_wait", Event_Selector_EPoll_process_wait, 3);
|
547
571
|
}
|