io-event 0.3.2 → 1.0.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: 66b02920cb810ad1ae4c312add97954e801c4f774a22cbaa278572a2985fdf2d
4
- data.tar.gz: daa403e0c8fdd4d5849b6d984ba65613d9d621724abc41a1201598cfb94004b1
3
+ metadata.gz: 19b363c469b81cd49232e4e91a07c26cd0883984b8b54aa3fb34c5d861d5c577
4
+ data.tar.gz: 050f76cc397e3ec9e44b861c6469ba37d845d6a11fbc05f390e32a12a24061b5
5
5
  SHA512:
6
- metadata.gz: d5ad6dc3b027d03c2cf97d96e89c37b01f80e7a8f2e2437c4add9958076a877f85ba01dd188829dec3f798b4608cc40ac8d9f755465a799bdbfe4d130e09a0eb
7
- data.tar.gz: 2a312b4ea5fc8d785a1233c087010608ca82e3834b198fbd08bb66a0ef88b3746d2da04b457841a4a848a35eeee5dc31c274a7a8b2da11f1f87ebe24ce694f0b
6
+ metadata.gz: 704987de2d3aa4107621717ef84e9aad8d06c0c0ba062e4f63b0f0ef40f11e86e2971fec26e2e95f45494d2c60045d1991cdaf26c92bb7580d98e4eea0a94be8
7
+ data.tar.gz: 1d6da8310ee63c3e6d821d2dbc5c23affe02015ba44daa1e999a71de6a929d7c274379fab981495e47ea82157bda22e1dfe1e5ffc36ba380a36cd8ac9c65515f
data/ext/IO_Event.bundle CHANGED
Binary file
data/ext/event.o CHANGED
Binary file
data/ext/interrupt.o CHANGED
Binary file
@@ -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;
@@ -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.2"
22
+ VERSION = "1.0.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.2
4
+ version: 1.0.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.3.0
124
124
  signing_key:
125
125
  specification_version: 4
126
126
  summary: An event loop.