event 0.7.0 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 71ed23db589d68545077cbf271afe2145054b040e3c8001b052366c8588a76e1
4
- data.tar.gz: 4c4e1e991044cc3abfbdd388dbfc6e4254de4ac3e97bec9faab60142c1f63525
3
+ metadata.gz: 3d1a02b3163aca45dcdb7ac4f3589e18894c3e753262d7934ea0f473c88e2a38
4
+ data.tar.gz: fac7fd3d48e616e1c03ca9cb6af19b8457c4dadb452261bb1f4b628d70297bcb
5
5
  SHA512:
6
- metadata.gz: 2f9ec25ff8d890e41589099ca347fc7c1ca1279dcc40c0065b759ac9e9c04ede4a9ad772f4beaadb794360b0af0a132db6f4e664ff36503995cc02a6ab3f7ff1
7
- data.tar.gz: 6767cd4dfc6bc9c69bcfdc9ecb08e327315480919805fcca78c31c32eed19a7decbbdd2fc858897b678db06d58d40d935e77697e0a67ca1ee8408188da02861a
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 "backend/backend.h"
22
+ #include "selector/selector.h"
23
23
 
24
24
  VALUE Event = Qnil;
25
- VALUE Event_Backend = Qnil;
25
+ VALUE Event_Selector = Qnil;
26
26
 
27
27
  void Init_event()
28
28
  {
29
- #ifdef HAVE_RB_EXT_RACTOR_SAFE
29
+ #ifdef HAVE_RB_EXT_RACTOR_SAFE
30
30
  rb_ext_ractor_safe(true);
31
- #endif
31
+ #endif
32
32
 
33
33
  Event = rb_define_module("Event");
34
- Event_Backend = rb_define_module_under(Event, "Backend");
34
+ Event_Selector = rb_define_module_under(Event, "Selector");
35
35
 
36
- Init_Event_Backend(Event_Backend);
36
+ Init_Event_Selector(Event_Selector);
37
37
 
38
- #ifdef EVENT_BACKEND_URING
39
- Init_Event_Backend_URing(Event_Backend);
38
+ #ifdef EVENT_SELECTOR_URING
39
+ Init_Event_Selector_URing(Event_Selector);
40
40
  #endif
41
41
 
42
- #ifdef EVENT_BACKEND_EPOLL
43
- Init_Event_Backend_EPoll(Event_Backend);
42
+ #ifdef EVENT_SELECTOR_EPOLL
43
+ Init_Event_Selector_EPoll(Event_Selector);
44
44
  #endif
45
45
 
46
- #ifdef EVENT_BACKEND_KQUEUE
47
- Init_Event_Backend_KQueue(Event_Backend);
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 "backend/uring.h"
30
+ #include "selector/uring.h"
31
31
  #endif
32
32
 
33
33
  #ifdef HAVE_SYS_EPOLL_H
34
- #include "backend/epoll.h"
34
+ #include "selector/epoll.h"
35
35
  #endif
36
36
 
37
37
  #ifdef HAVE_SYS_EVENT_H
38
- #include "backend/kqueue.h"
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", "backend/backend.c"]
34
- $VPATH << "$(srcdir)/backend"
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 << "backend/uring.c"
40
+ $srcs << "selector/uring.c"
40
41
  end
41
42
 
42
43
  if have_header('sys/epoll.h')
43
- $srcs << "backend/epoll.c"
44
+ $srcs << "selector/epoll.c"
44
45
  end
45
46
 
46
47
  if have_header('sys/event.h')
47
- $srcs << "backend/kqueue.c"
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 "backend.h"
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 Event_Backend_EPoll = Qnil;
30
+ static VALUE Event_Selector_EPoll = Qnil;
31
31
 
32
32
  enum {EPOLL_MAX_EVENTS = 64};
33
33
 
34
- struct Event_Backend_EPoll {
35
- struct Event_Backend backend;
34
+ struct Event_Selector_EPoll {
35
+ struct Event_Selector backend;
36
36
  int descriptor;
37
37
  };
38
38
 
39
- void Event_Backend_EPoll_Type_mark(void *_data)
39
+ void Event_Selector_EPoll_Type_mark(void *_data)
40
40
  {
41
- struct Event_Backend_EPoll *data = _data;
42
- Event_Backend_mark(&data->backend);
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 Event_Backend_EPoll *data) {
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 Event_Backend_EPoll_Type_free(void *_data)
53
+ void Event_Selector_EPoll_Type_free(void *_data)
54
54
  {
55
- struct Event_Backend_EPoll *data = _data;
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 Event_Backend_EPoll_Type_size(const void *data)
62
+ size_t Event_Selector_EPoll_Type_size(const void *data)
63
63
  {
64
- return sizeof(struct Event_Backend_EPoll);
64
+ return sizeof(struct Event_Selector_EPoll);
65
65
  }
66
66
 
67
- static const rb_data_type_t Event_Backend_EPoll_Type = {
67
+ static const rb_data_type_t Event_Selector_EPoll_Type = {
68
68
  .wrap_struct_name = "Event::Backend::EPoll",
69
69
  .function = {
70
- .dmark = Event_Backend_EPoll_Type_mark,
71
- .dfree = Event_Backend_EPoll_Type_free,
72
- .dsize = Event_Backend_EPoll_Type_size,
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 Event_Backend_EPoll_allocate(VALUE self) {
79
- struct Event_Backend_EPoll *data = NULL;
80
- VALUE instance = TypedData_Make_Struct(self, struct Event_Backend_EPoll, &Event_Backend_EPoll_Type, data);
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
- Event_Backend_initialize(&data->backend, Qnil);
82
+ Event_Selector_initialize(&data->backend, Qnil);
83
83
  data->descriptor = -1;
84
84
 
85
85
  return instance;
86
86
  }
87
87
 
88
- VALUE Event_Backend_EPoll_initialize(VALUE self, VALUE loop) {
89
- struct Event_Backend_EPoll *data = NULL;
90
- TypedData_Get_Struct(self, struct Event_Backend_EPoll, &Event_Backend_EPoll_Type, data);
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
- Event_Backend_initialize(&data->backend, loop);
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 Event_Backend_EPoll_close(VALUE self) {
107
- struct Event_Backend_EPoll *data = NULL;
108
- TypedData_Get_Struct(self, struct Event_Backend_EPoll, &Event_Backend_EPoll_Type, data);
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 Event_Backend_EPoll_transfer(VALUE self, VALUE fiber)
115
+ VALUE Event_Selector_EPoll_resume(int argc, VALUE *argv, VALUE self)
116
116
  {
117
- struct Event_Backend_EPoll *data = NULL;
118
- TypedData_Get_Struct(self, struct Event_Backend_EPoll, &Event_Backend_EPoll_Type, data);
117
+ struct Event_Selector_EPoll *data = NULL;
118
+ TypedData_Get_Struct(self, struct Event_Selector_EPoll, &Event_Selector_EPoll_Type, data);
119
119
 
120
- Event_Backend_wait_and_transfer(&data->backend, fiber);
120
+ Event_Selector_resume(&data->backend, argc, argv);
121
121
 
122
122
  return Qnil;
123
123
  }
124
124
 
125
- VALUE Event_Backend_EPoll_defer(VALUE self)
125
+ VALUE Event_Selector_EPoll_yield(VALUE self)
126
126
  {
127
- struct Event_Backend_EPoll *data = NULL;
128
- TypedData_Get_Struct(self, struct Event_Backend_EPoll, &Event_Backend_EPoll_Type, data);
127
+ struct Event_Selector_EPoll *data = NULL;
128
+ TypedData_Get_Struct(self, struct Event_Selector_EPoll, &Event_Selector_EPoll_Type, data);
129
129
 
130
- Event_Backend_defer(&data->backend);
130
+ Event_Selector_yield(&data->backend);
131
131
 
132
132
  return Qnil;
133
133
  }
134
134
 
135
- VALUE Event_Backend_EPoll_ready_p(VALUE self) {
136
- struct Event_Backend_EPoll *data = NULL;
137
- TypedData_Get_Struct(self, struct Event_Backend_EPoll, &Event_Backend_EPoll_Type, data);
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 Event_Backend_EPoll *data;
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
- Event_Backend_fiber_transfer(arguments->data->backend.loop);
171
+ Event_Selector_fiber_transfer(arguments->data->backend.loop, 0, NULL);
154
172
 
155
- return Event_Backend_process_status_wait(arguments->pid);
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 Event_Backend_EPoll_process_wait(VALUE self, VALUE fiber, VALUE pid, VALUE flags) {
170
- struct Event_Backend_EPoll *data = NULL;
171
- TypedData_Get_Struct(self, struct Event_Backend_EPoll, &Event_Backend_EPoll_Type, data);
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 & READABLE) flags |= EPOLLIN;
201
- if (events & PRIORITY) flags |= EPOLLPRI;
202
- if (events & WRITABLE) flags |= EPOLLOUT;
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 |= READABLE;
215
- if (flags & EPOLLPRI) events |= PRIORITY;
216
- if (flags & EPOLLOUT) events |= WRITABLE;
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 Event_Backend_EPoll *data;
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 = Event_Backend_fiber_transfer(arguments->data->backend.loop);
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 Event_Backend_EPoll_io_wait(VALUE self, VALUE fiber, VALUE io, VALUE events) {
252
- struct Event_Backend_EPoll *data = NULL;
253
- TypedData_Get_Struct(self, struct Event_Backend_EPoll, &Event_Backend_EPoll_Type, data);
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 = Event_Backend_io_descriptor(io);
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
- Event_Backend_EPoll_io_wait(arguments->self, arguments->fiber, arguments->io, RB_INT2NUM(READABLE));
347
+ Event_Selector_EPoll_io_wait(arguments->self, arguments->fiber, arguments->io, RB_INT2NUM(EVENT_READABLE));
330
348
  } else {
331
- rb_sys_fail("Event_Backend_EPoll_io_read");
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
- Event_Backend_nonblock_restore(arguments->descriptor, arguments->flags);
360
+ Event_Selector_nonblock_restore(arguments->descriptor, arguments->flags);
343
361
 
344
362
  return Qnil;
345
363
  }
346
364
 
347
- VALUE Event_Backend_EPoll_io_read(VALUE self, VALUE fiber, VALUE io, VALUE buffer, VALUE _length) {
348
- int descriptor = Event_Backend_io_descriptor(io);
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 = Event_Backend_nonblock_set(descriptor),
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
- Event_Backend_EPoll_io_wait(arguments->self, arguments->fiber, arguments->io, RB_INT2NUM(WRITABLE));
419
+ Event_Selector_EPoll_io_wait(arguments->self, arguments->fiber, arguments->io, RB_INT2NUM(EVENT_WRITABLE));
402
420
  } else {
403
- rb_sys_fail("Event_Backend_EPoll_io_write");
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
- Event_Backend_nonblock_restore(arguments->descriptor, arguments->flags);
432
+ Event_Selector_nonblock_restore(arguments->descriptor, arguments->flags);
415
433
 
416
434
  return Qnil;
417
435
  };
418
436
 
419
- VALUE Event_Backend_EPoll_io_write(VALUE self, VALUE fiber, VALUE io, VALUE buffer, VALUE _length) {
420
- int descriptor = Event_Backend_io_descriptor(io);
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 = Event_Backend_nonblock_set(descriptor),
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 Event_Backend_EPoll *data;
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 Event_Backend_EPoll_select(VALUE self, VALUE duration) {
496
- struct Event_Backend_EPoll *data = NULL;
497
- TypedData_Get_Struct(self, struct Event_Backend_EPoll, &Event_Backend_EPoll_Type, data);
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
- Event_Backend_ready_pop(&data->backend);
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
- if (arguments.count == 0) {
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 (!data->backend.ready && arguments.timeout != 0) {
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
- Event_Backend_fiber_transfer_result(fiber, result);
541
+ Event_Selector_fiber_transfer(fiber, 1, &result);
523
542
  }
524
543
 
525
544
  return INT2NUM(arguments.count);
526
545
  }
527
546
 
528
- void Init_Event_Backend_EPoll(VALUE Event_Backend) {
529
- Event_Backend_EPoll = rb_define_class_under(Event_Backend, "EPoll", rb_cObject);
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
- rb_define_alloc_func(Event_Backend_EPoll, Event_Backend_EPoll_allocate);
532
- rb_define_method(Event_Backend_EPoll, "initialize", Event_Backend_EPoll_initialize, 1);
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(Event_Backend_EPoll, "io_wait", Event_Backend_EPoll_io_wait, 3);
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(Event_Backend_EPoll, "io_read", Event_Backend_EPoll_io_read, 4);
543
- rb_define_method(Event_Backend_EPoll, "io_write", Event_Backend_EPoll_io_write, 4);
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(Event_Backend_EPoll, "process_wait", Event_Backend_EPoll_process_wait, 3);
570
+ rb_define_method(Event_Selector_EPoll, "process_wait", Event_Selector_EPoll_process_wait, 3);
547
571
  }