io-event 1.0.2 → 1.0.5

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: 050c0a061c54668eaf5d41eab6d70644410a0e6469b7e68cd26a6fa7c4a50f8a
4
- data.tar.gz: 22be34dad07b0f75fc68045ff17b92c29ffbebdc06e4f570d3f92758d8532192
3
+ metadata.gz: df3b3dcc41afd982188c85b96e4d63056ae5edb43c41a5f650f8af9d2e6d5bf1
4
+ data.tar.gz: d3b1ca8e0241b85517940941507163c2c0a1faff442908521e0749b1848d5820
5
5
  SHA512:
6
- metadata.gz: 92a187c8f2034aba8c33117fdc48a4055112cf1ea481a77d5fa7acc84683bedd04e295cb01e29c66ca2b23851debe8f86ec306d183c6c8474f5c44c2aef461da
7
- data.tar.gz: 9e4da7190480b3d56556c440ebf922134e139b93cdd8c6ca5f8b7cea24c15bb8b943e6437b0c492d135f76dfaec32d63cc3ed43987545436c116d43e16ca5c4c
6
+ metadata.gz: 0dcd4266b204828ed5514075ba2e00cdab0de2f20a63d8d37ee831493778b713e72ef51a97857fe1e3ec6761b1ba9f2a71bfb9e6b185249c18a1f6d9a3b28265
7
+ data.tar.gz: eaa160b9cb38c5564dad8b4b81971a6e8a30f27f409d8e547dff1514165eaced3d4954ea1db1ed33a4f22b2aeb82069aa7ad0755b84deb96d654a148904852b6
@@ -28,7 +28,9 @@
28
28
  #include "pidfd.c"
29
29
  #include "../interrupt.h"
30
30
 
31
- static const int DEBUG = 0;
31
+ enum {
32
+ DEBUG = 0,
33
+ };
32
34
 
33
35
  static VALUE IO_Event_Selector_EPoll = Qnil;
34
36
 
@@ -231,6 +233,11 @@ VALUE IO_Event_Selector_EPoll_process_wait(VALUE self, VALUE fiber, VALUE pid, V
231
233
  };
232
234
 
233
235
  process_wait_arguments.descriptor = pidfd_open(process_wait_arguments.pid, 0);
236
+
237
+ if (process_wait_arguments.descriptor == -1) {
238
+ rb_sys_fail("IO_Event_Selector_EPoll_process_wait:pidfd_open");
239
+ }
240
+
234
241
  rb_update_max_fd(process_wait_arguments.descriptor);
235
242
 
236
243
  struct epoll_event event = {
@@ -241,6 +248,7 @@ VALUE IO_Event_Selector_EPoll_process_wait(VALUE self, VALUE fiber, VALUE pid, V
241
248
  int result = epoll_ctl(data->descriptor, EPOLL_CTL_ADD, process_wait_arguments.descriptor, &event);
242
249
 
243
250
  if (result == -1) {
251
+ close(process_wait_arguments.descriptor);
244
252
  rb_sys_fail("IO_Event_Selector_EPoll_process_wait:epoll_ctl");
245
253
  }
246
254
 
@@ -319,24 +327,38 @@ VALUE IO_Event_Selector_EPoll_io_wait(VALUE self, VALUE fiber, VALUE io, VALUE e
319
327
  event.events = epoll_flags_from_events(NUM2INT(events));
320
328
  event.data.ptr = (void*)fiber;
321
329
 
322
- // fprintf(stderr, "<- fiber=%p descriptor=%d\n", (void*)fiber, descriptor);
330
+ if (DEBUG) fprintf(stderr, "<- fiber=%p descriptor=%d\n", (void*)fiber, descriptor);
323
331
 
324
332
  // A better approach is to batch all changes:
325
333
  int result = epoll_ctl(data->descriptor, EPOLL_CTL_ADD, descriptor, &event);
326
334
 
327
335
  if (result == -1 && errno == EEXIST) {
328
336
  // The file descriptor was already inserted into epoll.
329
- duplicate = descriptor = dup(descriptor);
330
-
331
- rb_update_max_fd(duplicate);
337
+ duplicate = dup(descriptor);
332
338
 
333
- if (descriptor == -1)
339
+ if (duplicate == -1) {
334
340
  rb_sys_fail("IO_Event_Selector_EPoll_io_wait:dup");
341
+ }
342
+
343
+ descriptor = duplicate;
344
+
345
+ rb_update_max_fd(descriptor);
335
346
 
336
347
  result = epoll_ctl(data->descriptor, EPOLL_CTL_ADD, descriptor, &event);
337
348
  }
338
349
 
339
350
  if (result == -1) {
351
+ // If we duplicated the file descriptor, ensure it's closed:
352
+ if (duplicate >= 0) {
353
+ close(duplicate);
354
+ }
355
+
356
+ if (errno == EPERM) {
357
+ IO_Event_Selector_queue_push(&data->backend, fiber);
358
+ IO_Event_Selector_yield(&data->backend);
359
+ return events;
360
+ }
361
+
340
362
  rb_sys_fail("IO_Event_Selector_EPoll_io_wait:epoll_ctl");
341
363
  }
342
364
 
@@ -21,6 +21,11 @@
21
21
  #include "selector.h"
22
22
  #include <fcntl.h>
23
23
 
24
+ #ifndef HAVE_RB_PROCESS_STATUS_WAIT
25
+ // Pull in WNOHANG.
26
+ #include <sys/wait.h>
27
+ #endif
28
+
24
29
  static const int DEBUG = 0;
25
30
 
26
31
  static ID id_transfer, id_alive_p;
@@ -47,12 +47,9 @@ module IO::Event
47
47
  @selector = nil
48
48
  end
49
49
 
50
- def transfer(fiber, *arguments)
51
- @selector.transfer(fiber, *arguments)
52
- end
53
-
54
- def transfer(*arguments)
55
- @selector.transfer(*arguments)
50
+ # Transfer from the calling fiber to the event loop.
51
+ def transfer
52
+ @selector.transfer
56
53
  end
57
54
 
58
55
  def resume(*arguments)
@@ -19,5 +19,5 @@
19
19
  # THE SOFTWARE.
20
20
 
21
21
  module IO::Event
22
- VERSION = "1.0.2"
22
+ VERSION = "1.0.5"
23
23
  end
metadata CHANGED
@@ -1,14 +1,17 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: io-event
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
8
+ - machty
9
+ - Benoit Daloze
10
+ - Delton Ding
8
11
  autorequire:
9
12
  bindir: bin
10
13
  cert_chain: []
11
- date: 2022-01-14 00:00:00.000000000 Z
14
+ date: 2022-03-13 00:00:00.000000000 Z
12
15
  dependencies:
13
16
  - !ruby/object:Gem::Dependency
14
17
  name: bake