io-event 0.3.1 → 0.5.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: dd0859ac56f4bcd713026e8e7faa0547ec57d195c35abe8d6bcfa77dda89f25d
4
- data.tar.gz: 1d6c6debea4d7a822f383e5d3b7c1ed0698b5928b2637ad65069b0798ea557d8
3
+ metadata.gz: 82ae60c9c790437fc720a98489a0edcc345cca0420d795b2e33dcd8729f30dd2
4
+ data.tar.gz: f1a585938bb11cab9dd29a5acb50831feadce6e60d515112d2e8b22fdda5f65b
5
5
  SHA512:
6
- metadata.gz: 2edfbfddcecac51db0093e30df9b04ac49fceb2cef189b8d46cfecc564ac47f3ef4c1680632cfb4ab0266e6529472764dc6ac81b0ae715f0b4a7707e8c4d9acd
7
- data.tar.gz: a2bb38d0bf5a7cde138c94f2cd799be2a184b035c70e88e24f32dca91e20051473594fea7883c223ceb612e71beb499f9d81ef6335e4469f313b0de6fd31947b
6
+ metadata.gz: 34578267eccd7ae7c7c902f44db64f2be4a63e596c4c4522ed2199a5fd4c1247f1bcf31b02b0b2c21a8aa2856979c45421f86a01f0fbd32b824f5df91dd1ab7f
7
+ data.tar.gz: 3d4f4acd7739cc67c04e65c4a6f4079bd0d887c50cbb13f0d979b4d7f7f94916dc6067f93a33b8a63c67cae45b0f0743c2b9f4af4e46b1e33a7397910026ee86
data/ext/IO_Event.bundle CHANGED
Binary file
data/ext/event.o CHANGED
Binary file
data/ext/interrupt.o CHANGED
Binary file
data/ext/io/event/event.c CHANGED
@@ -24,7 +24,7 @@
24
24
  VALUE IO_Event = Qnil;
25
25
  VALUE IO_Event_Selector = Qnil;
26
26
 
27
- void Init_IO_Event()
27
+ void Init_IO_Event(void)
28
28
  {
29
29
  #ifdef HAVE_RB_EXT_RACTOR_SAFE
30
30
  rb_ext_ractor_safe(true);
data/ext/io/event/event.h CHANGED
@@ -24,7 +24,7 @@
24
24
 
25
25
  #include "extconf.h"
26
26
 
27
- void Init_IO_Event();
27
+ void Init_IO_Event(void);
28
28
 
29
29
  #ifdef HAVE_LIBURING_H
30
30
  #include "selector/uring.h"
@@ -365,7 +365,7 @@ VALUE io_read_loop(VALUE _arguments) {
365
365
 
366
366
  void *base;
367
367
  size_t size;
368
- rb_io_buffer_get_mutable(arguments->buffer, &base, &size);
368
+ rb_io_buffer_get_bytes_for_writing(arguments->buffer, &base, &size);
369
369
 
370
370
  size_t offset = 0;
371
371
  size_t length = arguments->length;
@@ -380,10 +380,10 @@ VALUE io_read_loop(VALUE _arguments) {
380
380
  length -= result;
381
381
  } else if (result == 0) {
382
382
  break;
383
- } else if (length > 0 && IO_Event_try_again(-result)) {
383
+ } else if (length > 0 && IO_Event_try_again(errno)) {
384
384
  IO_Event_Selector_EPoll_io_wait(arguments->self, arguments->fiber, arguments->io, RB_INT2NUM(IO_EVENT_READABLE));
385
385
  } else {
386
- return rb_fiber_scheduler_io_result(-1, -result);
386
+ return rb_fiber_scheduler_io_result(-1, errno);
387
387
  }
388
388
  }
389
389
 
@@ -437,7 +437,7 @@ VALUE io_write_loop(VALUE _arguments) {
437
437
 
438
438
  const void *base;
439
439
  size_t size;
440
- rb_io_buffer_get_immutable(arguments->buffer, &base, &size);
440
+ rb_io_buffer_get_bytes_for_reading(arguments->buffer, &base, &size);
441
441
 
442
442
  size_t offset = 0;
443
443
  size_t length = arguments->length;
@@ -540,7 +540,11 @@ void select_internal_without_gvl(struct select_arguments *arguments) {
540
540
  arguments->data->blocked = 0;
541
541
 
542
542
  if (arguments->count == -1) {
543
- rb_sys_fail("select_internal_without_gvl:epoll_wait");
543
+ if (errno != EINTR) {
544
+ rb_sys_fail("select_internal_without_gvl:epoll_wait");
545
+ } else {
546
+ arguments->count = 0;
547
+ }
544
548
  }
545
549
  }
546
550
 
@@ -549,7 +553,11 @@ void select_internal_with_gvl(struct select_arguments *arguments) {
549
553
  select_internal((void *)arguments);
550
554
 
551
555
  if (arguments->count == -1) {
552
- rb_sys_fail("select_internal_with_gvl:epoll_wait");
556
+ if (errno != EINTR) {
557
+ rb_sys_fail("select_internal_with_gvl:epoll_wait");
558
+ } else {
559
+ arguments->count = 0;
560
+ }
553
561
  }
554
562
  }
555
563
 
@@ -396,7 +396,7 @@ VALUE io_read_loop(VALUE _arguments) {
396
396
 
397
397
  void *base;
398
398
  size_t size;
399
- rb_io_buffer_get_mutable(arguments->buffer, &base, &size);
399
+ rb_io_buffer_get_bytes_for_writing(arguments->buffer, &base, &size);
400
400
 
401
401
  size_t offset = 0;
402
402
  size_t length = arguments->length;
@@ -478,7 +478,7 @@ VALUE io_write_loop(VALUE _arguments) {
478
478
 
479
479
  const void *base;
480
480
  size_t size;
481
- rb_io_buffer_get_immutable(arguments->buffer, &base, &size);
481
+ rb_io_buffer_get_bytes_for_reading(arguments->buffer, &base, &size);
482
482
 
483
483
  size_t offset = 0;
484
484
  size_t length = arguments->length;
@@ -605,7 +605,11 @@ void select_internal_without_gvl(struct select_arguments *arguments) {
605
605
  arguments->data->blocked = 0;
606
606
 
607
607
  if (arguments->count == -1) {
608
- rb_sys_fail("select_internal_without_gvl:kevent");
608
+ if (errno != EINTR) {
609
+ rb_sys_fail("select_internal_without_gvl:kevent");
610
+ } else {
611
+ arguments->count = 0;
612
+ }
609
613
  }
610
614
  }
611
615
 
@@ -614,7 +618,11 @@ void select_internal_with_gvl(struct select_arguments *arguments) {
614
618
  select_internal((void *)arguments);
615
619
 
616
620
  if (arguments->count == -1) {
617
- rb_sys_fail("select_internal_with_gvl:kevent");
621
+ if (errno != EINTR) {
622
+ rb_sys_fail("select_internal_with_gvl:kevent");
623
+ } else {
624
+ arguments->count = 0;
625
+ }
618
626
  }
619
627
  }
620
628
 
@@ -27,7 +27,12 @@
27
27
 
28
28
  #include "pidfd.c"
29
29
 
30
- static const int DEBUG = 0;
30
+ #include <linux/version.h>
31
+
32
+ enum {
33
+ DEBUG = 0,
34
+ DEBUG_IO_READ = 0,
35
+ };
31
36
 
32
37
  static VALUE IO_Event_Selector_URing = Qnil;
33
38
 
@@ -368,12 +373,28 @@ VALUE IO_Event_Selector_URing_io_wait(VALUE self, VALUE fiber, VALUE io, VALUE e
368
373
 
369
374
  #ifdef HAVE_RUBY_IO_BUFFER_H
370
375
 
376
+ #if LINUX_VERSION_CODE >= KERNEL_VERSION(5,16,0)
377
+ static inline off_t io_seekable(int descriptor) {
378
+ return -1;
379
+ }
380
+ #else
381
+ #warning Upgrade your kernel to 5.16! io_uring bugs prevent efficient io_read/io_write hooks.
382
+ static inline off_t io_seekable(int descriptor)
383
+ {
384
+ if (lseek(descriptor, 0, SEEK_CUR) == -1) {
385
+ return 0;
386
+ } else {
387
+ return -1;
388
+ }
389
+ }
390
+ #endif
391
+
371
392
  static int io_read(struct IO_Event_Selector_URing *data, VALUE fiber, int descriptor, char *buffer, size_t length) {
372
393
  struct io_uring_sqe *sqe = io_get_sqe(data);
373
394
 
374
395
  if (DEBUG) fprintf(stderr, "io_read:io_uring_prep_read(fiber=%p)\n", (void*)fiber);
375
396
 
376
- io_uring_prep_read(sqe, descriptor, buffer, length, 0);
397
+ io_uring_prep_read(sqe, descriptor, buffer, length, io_seekable(descriptor));
377
398
  io_uring_sqe_set_data(sqe, (void*)fiber);
378
399
  io_uring_submit_now(data);
379
400
 
@@ -391,14 +412,16 @@ VALUE IO_Event_Selector_URing_io_read(VALUE self, VALUE fiber, VALUE io, VALUE b
391
412
 
392
413
  void *base;
393
414
  size_t size;
394
- rb_io_buffer_get_mutable(buffer, &base, &size);
415
+ rb_io_buffer_get_bytes_for_writing(buffer, &base, &size);
395
416
 
396
417
  size_t offset = 0;
397
418
  size_t length = NUM2SIZET(_length);
398
419
 
399
420
  while (true) {
400
421
  size_t maximum_size = size - offset;
422
+ if (DEBUG_IO_READ) fprintf(stderr, "io_read(%d, +%ld, %ld)\n", descriptor, offset, maximum_size);
401
423
  int result = io_read(data, fiber, descriptor, (char*)base+offset, maximum_size);
424
+ if (DEBUG_IO_READ) fprintf(stderr, "io_read(%d, +%ld, %ld) -> %d\n", descriptor, offset, maximum_size, result);
402
425
 
403
426
  if (result > 0) {
404
427
  offset += result;
@@ -422,7 +445,7 @@ int io_write(struct IO_Event_Selector_URing *data, VALUE fiber, int descriptor,
422
445
 
423
446
  if (DEBUG) fprintf(stderr, "io_write:io_uring_prep_write(fiber=%p)\n", (void*)fiber);
424
447
 
425
- io_uring_prep_write(sqe, descriptor, buffer, length, 0);
448
+ io_uring_prep_write(sqe, descriptor, buffer, length, io_seekable(descriptor));
426
449
  io_uring_sqe_set_data(sqe, (void*)fiber);
427
450
  io_uring_submit_pending(data);
428
451
 
@@ -440,7 +463,7 @@ VALUE IO_Event_Selector_URing_io_write(VALUE self, VALUE fiber, VALUE io, VALUE
440
463
 
441
464
  const void *base;
442
465
  size_t size;
443
- rb_io_buffer_get_immutable(buffer, &base, &size);
466
+ rb_io_buffer_get_bytes_for_reading(buffer, &base, &size);
444
467
 
445
468
  size_t offset = 0;
446
469
  size_t length = NUM2SIZET(_length);
@@ -553,6 +576,8 @@ int select_internal_without_gvl(struct select_arguments *arguments) {
553
576
 
554
577
  if (arguments->result == -ETIME) {
555
578
  arguments->result = 0;
579
+ } else if (arguments->result == -EINTR) {
580
+ arguments->result = 0;
556
581
  } else if (arguments->result < 0) {
557
582
  rb_syserr_fail(-arguments->result, "select_internal_without_gvl:io_uring_wait_cqe_timeout");
558
583
  } else {
@@ -563,8 +588,6 @@ int select_internal_without_gvl(struct select_arguments *arguments) {
563
588
  return arguments->result;
564
589
  }
565
590
 
566
- // #define IO_EVENT_SELECTOR_URING_UDATA_INTERRUPT ((__u64) -2)
567
-
568
591
  static inline
569
592
  unsigned select_process_completions(struct io_uring *ring) {
570
593
  unsigned completed = 0;
@@ -580,10 +603,6 @@ unsigned select_process_completions(struct io_uring *ring) {
580
603
  continue;
581
604
  }
582
605
 
583
- // if (cqe->user_data == IO_EVENT_SELECTOR_URING_UDATA_INTERRUPT) {
584
- // io_uring_cq_advance(ring, 1);
585
- // }
586
-
587
606
  VALUE fiber = (VALUE)cqe->user_data;
588
607
  VALUE result = RB_INT2NUM(cqe->res);
589
608
 
data/ext/kqueue.o CHANGED
Binary file
data/ext/selector.o CHANGED
Binary file
@@ -158,7 +158,7 @@ module IO::Event
158
158
  else
159
159
  break unless result
160
160
 
161
- buffer.copy(result, offset)
161
+ buffer.set_string(result, offset)
162
162
 
163
163
  size = result.bytesize
164
164
  offset += size
@@ -176,7 +176,7 @@ module IO::Event
176
176
  while true
177
177
  maximum_size = buffer.size - offset
178
178
 
179
- chunk = buffer.to_str(offset, maximum_size)
179
+ chunk = buffer.get_string(offset, maximum_size)
180
180
  case result = blocking{io.write_nonblock(chunk, exception: false)}
181
181
  when :wait_readable
182
182
  if length > 0
@@ -31,12 +31,10 @@ module IO::Event
31
31
  end
32
32
  end
33
33
 
34
- if self.const_defined?(:URing)
35
- return URing
34
+ if self.const_defined?(:EPoll)
35
+ return EPoll
36
36
  elsif self.const_defined?(:KQueue)
37
37
  return KQueue
38
- elsif self.const_defined?(:EPoll)
39
- return EPoll
40
38
  else
41
39
  return Select
42
40
  end
@@ -19,5 +19,5 @@
19
19
  # THE SOFTWARE.
20
20
 
21
21
  module IO::Event
22
- VERSION = "0.3.1"
22
+ VERSION = "0.5.0"
23
23
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: io-event
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.5.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-12-18 00:00:00.000000000 Z
11
+ date: 2021-12-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bake
@@ -113,14 +113,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
113
113
  requirements:
114
114
  - - ">="
115
115
  - !ruby/object:Gem::Version
116
- version: '0'
116
+ version: '3.0'
117
117
  required_rubygems_version: !ruby/object:Gem::Requirement
118
118
  requirements:
119
119
  - - ">="
120
120
  - !ruby/object:Gem::Version
121
121
  version: '0'
122
122
  requirements: []
123
- rubygems_version: 3.3.0.dev
123
+ rubygems_version: 3.2.32
124
124
  signing_key:
125
125
  specification_version: 4
126
126
  summary: An event loop.