event 0.7.0 → 0.8.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: bbc589826b45d926acc5b2e3fd2ef49f67832b8e64562b5d860b43a74f850b72
4
+ data.tar.gz: 66ae0f0df1693d58cd6929ca8187ad2f0b9892920555d28595d7a0f94c07ffd4
5
5
  SHA512:
6
- metadata.gz: 2f9ec25ff8d890e41589099ca347fc7c1ca1279dcc40c0065b759ac9e9c04ede4a9ad772f4beaadb794360b0af0a132db6f4e664ff36503995cc02a6ab3f7ff1
7
- data.tar.gz: 6767cd4dfc6bc9c69bcfdc9ecb08e327315480919805fcca78c31c32eed19a7decbbdd2fc858897b678db06d58d40d935e77697e0a67ca1ee8408188da02861a
6
+ metadata.gz: 47addf50f1785a0f632776536186c7b6575de70bf4b4cdcf4f0ab816e6455737615f3ce3640980c3da23971f7f24509652c4c3aed898220f86fa7f394c4f549b
7
+ data.tar.gz: c584fbaa4b9fb3c73e6ed31c7eeaf86c8da69402d4233d2790e7cb0c4fbe31bf9d0ebabca0b94a855ae55da0dc18eeba77e83dfa7e8deb8d270e9a5c1b9b85f5
data/ext/event/Makefile CHANGED
@@ -16,7 +16,7 @@ topdir = /Users/samuel/.rubies/ruby-3.0.1/include/ruby-3.0.0
16
16
  hdrdir = $(topdir)
17
17
  arch_hdrdir = /Users/samuel/.rubies/ruby-3.0.1/include/ruby-3.0.0/x86_64-darwin20
18
18
  PATH_SEPARATOR = :
19
- VPATH = $(srcdir):$(arch_hdrdir)/ruby:$(hdrdir)/ruby:$(srcdir)/backend
19
+ VPATH = $(srcdir):$(arch_hdrdir)/ruby:$(hdrdir)/ruby:$(srcdir)/selector
20
20
  prefix = $(DESTDIR)/Users/samuel/.rubies/ruby-3.0.1
21
21
  rubysitearchprefix = $(rubylibprefix)/$(sitearch)
22
22
  rubyarchprefix = $(rubylibprefix)/$(arch)
@@ -139,8 +139,8 @@ target_prefix = /event
139
139
  LOCAL_LIBS =
140
140
  LIBS =
141
141
  ORIG_SRCS = event.c
142
- SRCS = $(ORIG_SRCS) event.c backend.c kqueue.c
143
- OBJS = event.o backend.o kqueue.o
142
+ SRCS = $(ORIG_SRCS) event.c selector.c kqueue.c
143
+ OBJS = event.o selector.o kqueue.o
144
144
  HDRS = $(srcdir)/event.h $(srcdir)/extconf.h
145
145
  LOCAL_HDRS =
146
146
  TARGET = event
Binary file
data/ext/event/event.c CHANGED
@@ -19,10 +19,10 @@
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
  {
@@ -31,19 +31,19 @@ void Init_event()
31
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/event.o CHANGED
Binary file
data/ext/event/extconf.rb CHANGED
@@ -30,25 +30,26 @@ 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
36
  have_func('&rb_fiber_transfer')
37
37
 
38
38
  if have_library('uring') and have_header('liburing.h')
39
- $srcs << "backend/uring.c"
39
+ $srcs << "selector/uring.c"
40
40
  end
41
41
 
42
42
  if have_header('sys/epoll.h')
43
- $srcs << "backend/epoll.c"
43
+ $srcs << "selector/epoll.c"
44
44
  end
45
45
 
46
46
  if have_header('sys/event.h')
47
- $srcs << "backend/kqueue.c"
47
+ $srcs << "selector/kqueue.c"
48
48
  end
49
49
 
50
50
  have_func("rb_io_descriptor")
51
51
  have_func("&rb_process_status_wait")
52
+ have_func("&rb_fiber_raise")
52
53
 
53
54
  have_header('ruby/io/buffer.h')
54
55
 
data/ext/event/kqueue.o CHANGED
Binary file
data/ext/event/mkmf.log CHANGED
@@ -118,7 +118,7 @@ checked program was:
118
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
119
  Undefined symbols for architecture x86_64:
120
120
  "_rb_io_descriptor", referenced from:
121
- _t in conftest-9dccb6.o
121
+ _t in conftest-839f76.o
122
122
  ld: symbol(s) not found for architecture x86_64
123
123
  clang: error: linker command failed with exit code 1 (use -v to see invocation)
124
124
  checked program was:
@@ -169,6 +169,37 @@ checked program was:
169
169
 
170
170
  --------------------
171
171
 
172
+ have_func: checking for &rb_fiber_raise()... -------------------- no
173
+
174
+ "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 "
175
+ conftest.c:14:76: error: use of undeclared identifier 'rb_fiber_raise'; did you mean 'rb_fiber_resume'?
176
+ int t(void) { const volatile void *volatile p; p = (const volatile void *)&rb_fiber_raise; return !p; }
177
+ ^~~~~~~~~~~~~~
178
+ rb_fiber_resume
179
+ /Users/samuel/.rubies/ruby-3.0.1/include/ruby-3.0.0/ruby/internal/intern/cont.h:32:7: note: 'rb_fiber_resume' declared here
180
+ VALUE rb_fiber_resume(VALUE fib, int argc, const VALUE *argv);
181
+ ^
182
+ 1 error generated.
183
+ checked program was:
184
+ /* begin */
185
+ 1: #include "ruby.h"
186
+ 2:
187
+ 3: /*top*/
188
+ 4: extern int t(void);
189
+ 5: int main(int argc, char **argv)
190
+ 6: {
191
+ 7: if (argc > 1000000) {
192
+ 8: int (* volatile tp)(void)=(int (*)(void))&t;
193
+ 9: printf("%d", (*tp)());
194
+ 10: }
195
+ 11:
196
+ 12: return !!argv[argc];
197
+ 13: }
198
+ 14: int t(void) { const volatile void *volatile p; p = (const volatile void *)&rb_fiber_raise; return !p; }
199
+ /* end */
200
+
201
+ --------------------
202
+
172
203
  have_header: checking for ruby/io/buffer.h... -------------------- no
173
204
 
174
205
  "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"
Binary file
@@ -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_transfer(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_wait_and_transfer(&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,
@@ -505,10 +523,10 @@ VALUE Event_Backend_EPoll_select(VALUE self, VALUE duration) {
505
523
 
506
524
  select_internal_with_gvl(&arguments);
507
525
 
508
- if (arguments.count == 0) {
526
+ if (!ready && arguments.count == 0) {
509
527
  arguments.timeout = make_timeout(duration);
510
528
 
511
- if (!data->backend.ready && arguments.timeout != 0) {
529
+ if (arguments.timeout != 0) {
512
530
  select_internal_without_gvl(&arguments);
513
531
  }
514
532
  }
@@ -519,29 +537,34 @@ VALUE Event_Backend_EPoll_select(VALUE self, VALUE duration) {
519
537
 
520
538
  // fprintf(stderr, "-> fiber=%p descriptor=%d\n", (void*)fiber, events[i].data.fd);
521
539
 
522
- Event_Backend_fiber_transfer_result(fiber, result);
540
+ Event_Selector_fiber_transfer(fiber, 1, &result);
523
541
  }
524
542
 
525
543
  return INT2NUM(arguments.count);
526
544
  }
527
545
 
528
- void Init_Event_Backend_EPoll(VALUE Event_Backend) {
529
- Event_Backend_EPoll = rb_define_class_under(Event_Backend, "EPoll", rb_cObject);
546
+ void Init_Event_Selector_EPoll(VALUE Event_Selector) {
547
+ Event_Selector_EPoll = rb_define_class_under(Event_Selector, "EPoll", rb_cObject);
548
+
549
+ rb_define_alloc_func(Event_Selector_EPoll, Event_Selector_EPoll_allocate);
550
+ rb_define_method(Event_Selector_EPoll, "initialize", Event_Selector_EPoll_initialize, 1);
551
+
552
+ rb_define_method(Event_Selector_EPoll, "transfer", Event_Selector_EPoll_transfer, -1);
553
+ rb_define_method(Event_Selector_EPoll, "yield", Event_Selector_EPoll_yield, 0);
554
+ rb_define_method(Event_Selector_EPoll, "push", Event_Selector_EPoll_push, 1);
555
+ rb_define_method(Event_Selector_EPoll, "raise", Event_Selector_EPoll_raise, -1);
556
+
557
+ rb_define_method(Event_Selector_EPoll, "ready?", Event_Selector_EPoll_ready_p, 0);
530
558
 
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);
559
+ rb_define_method(Event_Selector_EPoll, "select", Event_Selector_EPoll_select, 1);
560
+ rb_define_method(Event_Selector_EPoll, "close", Event_Selector_EPoll_close, 0);
538
561
 
539
- rb_define_method(Event_Backend_EPoll, "io_wait", Event_Backend_EPoll_io_wait, 3);
562
+ rb_define_method(Event_Selector_EPoll, "io_wait", Event_Selector_EPoll_io_wait, 3);
540
563
 
541
564
  #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);
565
+ rb_define_method(Event_Selector_EPoll, "io_read", Event_Selector_EPoll_io_read, 4);
566
+ rb_define_method(Event_Selector_EPoll, "io_write", Event_Selector_EPoll_io_write, 4);
544
567
  #endif
545
568
 
546
- rb_define_method(Event_Backend_EPoll, "process_wait", Event_Backend_EPoll_process_wait, 3);
569
+ rb_define_method(Event_Selector_EPoll, "process_wait", Event_Selector_EPoll_process_wait, 3);
547
570
  }