io-event 1.1.7 → 1.2.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: 0202b38104b1b6254a15fc12f687f9102509ba75592b1584d3dd5d0e44c497fb
4
- data.tar.gz: 925de8b198ea2a9fca99b7c02c5262dd691a9864601c7db109a79c332804b944
3
+ metadata.gz: c19fdf43c5e63eb628c4ebb1feedcd048eac2e3ec4b83571f05bcb239eed9d02
4
+ data.tar.gz: 141749bc238099c65ebcc6db1d0d8b8ce1c3477e6e11a9f62e6c50572b9b6d84
5
5
  SHA512:
6
- metadata.gz: d0bb87512e17c8be8ca0b04390466b0c3de198c6ee4a4a0a074b31d8e2f3bb0f482ece3378d0d9653b9219d36f06d41882f4c78631b27f6c0fb02e4143688d33
7
- data.tar.gz: 4403550628403eccfb92d60e44ccf096ecb2dee1f2e78917fbef65b8c49cc71b15db96b3074e5b16f0ce005f826db928e4a95fd1214973cf33509659195a2e9a
6
+ metadata.gz: c3da16be3fd6a0f98106f3e263ff2229e61a03bf5660fee1d3bb1bf6c191f1fd7475aabb85c8b5c29b25f6205816c728b42d68c74e4a123cea6810ac7be44b23
7
+ data.tar.gz: '026937a0ad18ba0f2783a8e8b8624177e8fbae34ca1a52eb2c5ccd59ae8231d4eea192fc3cc6b54d60e7d5d40d630f97754afa12e115f9ac44bd79caa9e52eee'
checksums.yaml.gz.sig CHANGED
Binary file
data/ext/extconf.rb CHANGED
@@ -63,6 +63,7 @@ have_func("rb_io_descriptor")
63
63
  have_func("&rb_process_status_wait")
64
64
  have_func("rb_fiber_current")
65
65
  have_func("&rb_fiber_raise")
66
+ have_func("epoll_pwait2")
66
67
 
67
68
  have_header('ruby/io/buffer.h')
68
69
 
@@ -569,6 +569,38 @@ VALUE IO_Event_Selector_EPoll_io_write_compatible(int argc, VALUE *argv, VALUE s
569
569
 
570
570
  #endif
571
571
 
572
+ #if defined(HAVE_EPOLL_PWAIT2)
573
+ static
574
+ struct timespec * make_timeout(VALUE duration, struct timespec * storage) {
575
+ if (duration == Qnil) {
576
+ return NULL;
577
+ }
578
+
579
+ if (FIXNUM_P(duration)) {
580
+ storage->tv_sec = NUM2TIMET(duration);
581
+ storage->tv_nsec = 0;
582
+
583
+ return storage;
584
+ }
585
+
586
+ else if (RB_FLOAT_TYPE_P(duration)) {
587
+ double value = RFLOAT_VALUE(duration);
588
+ time_t seconds = value;
589
+
590
+ storage->tv_sec = seconds;
591
+ storage->tv_nsec = (value - seconds) * 1000000000L;
592
+
593
+ return storage;
594
+ }
595
+
596
+ rb_raise(rb_eRuntimeError, "unable to convert timeout");
597
+ }
598
+
599
+ static
600
+ int timeout_nonblocking(struct timespec * timespec) {
601
+ return timespec && timespec->tv_sec == 0 && timespec->tv_nsec == 0;
602
+ }
603
+ #else
572
604
  static
573
605
  int make_timeout(VALUE duration) {
574
606
  if (duration == Qnil) {
@@ -588,20 +620,35 @@ int make_timeout(VALUE duration) {
588
620
  rb_raise(rb_eRuntimeError, "unable to convert timeout");
589
621
  }
590
622
 
623
+ static
624
+ int timeout_nonblocking(int timeout) {
625
+ return timeout == 0;
626
+ }
627
+ #endif
628
+
591
629
  struct select_arguments {
592
630
  struct IO_Event_Selector_EPoll *data;
593
631
 
594
632
  int count;
595
633
  struct epoll_event events[EPOLL_MAX_EVENTS];
596
-
634
+
635
+ #if defined(HAVE_EPOLL_PWAIT2)
636
+ struct timespec * timeout;
637
+ struct timespec storage;
638
+ #else
597
639
  int timeout;
640
+ #endif
598
641
  };
599
642
 
600
643
  static
601
644
  void * select_internal(void *_arguments) {
602
645
  struct select_arguments * arguments = (struct select_arguments *)_arguments;
603
646
 
647
+ #if defined(HAVE_EPOLL_PWAIT2)
648
+ arguments->count = epoll_pwait2(arguments->data->descriptor, arguments->events, EPOLL_MAX_EVENTS, arguments->timeout, NULL);
649
+ #else
604
650
  arguments->count = epoll_wait(arguments->data->descriptor, arguments->events, EPOLL_MAX_EVENTS, arguments->timeout);
651
+ #endif
605
652
 
606
653
  return NULL;
607
654
  }
@@ -642,9 +689,20 @@ VALUE IO_Event_Selector_EPoll_select(VALUE self, VALUE duration) {
642
689
 
643
690
  struct select_arguments arguments = {
644
691
  .data = data,
692
+ #if defined(HAVE_EPOLL_PWAIT2)
693
+ .storage = {
694
+ .tv_sec = 0,
695
+ .tv_nsec = 0
696
+ }
697
+ #else
645
698
  .timeout = 0
699
+ #endif
646
700
  };
647
701
 
702
+ #if defined(HAVE_EPOLL_PWAIT2)
703
+ arguments.timeout = &arguments.storage;
704
+ #endif
705
+
648
706
  // Process any currently pending events:
649
707
  select_internal_with_gvl(&arguments);
650
708
 
@@ -654,9 +712,13 @@ VALUE IO_Event_Selector_EPoll_select(VALUE self, VALUE duration) {
654
712
  // 3. There are no items in the ready list,
655
713
  // then we can perform a blocking select.
656
714
  if (!ready && !arguments.count && !data->backend.ready) {
715
+ #if defined(HAVE_EPOLL_PWAIT2)
716
+ arguments.timeout = make_timeout(duration, &arguments.storage);
717
+ #else
657
718
  arguments.timeout = make_timeout(duration);
719
+ #endif
658
720
 
659
- if (arguments.timeout != 0) {
721
+ if (!timeout_nonblocking(arguments.timeout)) {
660
722
  // Wait for events to occur
661
723
  select_internal_without_gvl(&arguments);
662
724
  }
@@ -43,7 +43,7 @@ enum IO_Event {
43
43
  IO_EVENT_HANGUP = 16
44
44
  };
45
45
 
46
- void Init_IO_Event_Selector();
46
+ void Init_IO_Event_Selector(VALUE IO_Event_Selector);
47
47
 
48
48
  static inline int IO_Event_try_again(int error) {
49
49
  return error == EAGAIN || error == EWOULDBLOCK;
@@ -5,6 +5,6 @@
5
5
 
6
6
  class IO
7
7
  module Event
8
- VERSION = "1.1.7"
8
+ VERSION = "1.2.0"
9
9
  end
10
10
  end
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: io-event
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.7
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
@@ -41,7 +41,7 @@ cert_chain:
41
41
  Q2K9NVun/S785AP05vKkXZEFYxqG6EW012U4oLcFl5MySFajYXRYbuUpH6AY+HP8
42
42
  voD0MPg1DssDLKwXyt1eKD/+Fq0bFWhwVM/1XiAXL7lyYUyOq24KHgQ2Csg=
43
43
  -----END CERTIFICATE-----
44
- date: 2023-03-11 00:00:00.000000000 Z
44
+ date: 2023-04-30 00:00:00.000000000 Z
45
45
  dependencies:
46
46
  - !ruby/object:Gem::Dependency
47
47
  name: bake
@@ -150,7 +150,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
150
150
  - !ruby/object:Gem::Version
151
151
  version: '0'
152
152
  requirements: []
153
- rubygems_version: 3.4.6
153
+ rubygems_version: 3.4.10
154
154
  signing_key:
155
155
  specification_version: 4
156
156
  summary: An event loop.
metadata.gz.sig CHANGED
Binary file