io-event 1.2.0 → 1.2.1

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: c19fdf43c5e63eb628c4ebb1feedcd048eac2e3ec4b83571f05bcb239eed9d02
4
- data.tar.gz: 141749bc238099c65ebcc6db1d0d8b8ce1c3477e6e11a9f62e6c50572b9b6d84
3
+ metadata.gz: 02cbd4beff5335467997d91cbdc8e3bbf509947a15e2f36636b3e4e29b7cd91e
4
+ data.tar.gz: 9ca1138136d115d1fdfd4e41446f6f7b684de878ec6a7834f27a9ea6ba210896
5
5
  SHA512:
6
- metadata.gz: c3da16be3fd6a0f98106f3e263ff2229e61a03bf5660fee1d3bb1bf6c191f1fd7475aabb85c8b5c29b25f6205816c728b42d68c74e4a123cea6810ac7be44b23
7
- data.tar.gz: '026937a0ad18ba0f2783a8e8b8624177e8fbae34ca1a52eb2c5ccd59ae8231d4eea192fc3cc6b54d60e7d5d40d630f97754afa12e115f9ac44bd79caa9e52eee'
6
+ metadata.gz: 5fe958c76100f346101702b285b140bebe3a149525288cf8e83a1a1806a710928627e8c2d5ae4d8ec716836c264d6f645daa77b944ce1d59a5aaef6ac572e7aa
7
+ data.tar.gz: 9ce5953f7c6c3fba1e41e61fcc4ae7e24a294624a004fc532724fd49c707afc14a837359547df45611e0df6ab35e9d954e6f8e09eed748c845ad6ed8a6b61076
checksums.yaml.gz.sig CHANGED
Binary file
@@ -569,7 +569,6 @@ 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
572
  static
574
573
  struct timespec * make_timeout(VALUE duration, struct timespec * storage) {
575
574
  if (duration == Qnil) {
@@ -600,31 +599,6 @@ static
600
599
  int timeout_nonblocking(struct timespec * timespec) {
601
600
  return timespec && timespec->tv_sec == 0 && timespec->tv_nsec == 0;
602
601
  }
603
- #else
604
- static
605
- int make_timeout(VALUE duration) {
606
- if (duration == Qnil) {
607
- return -1;
608
- }
609
-
610
- if (FIXNUM_P(duration)) {
611
- return NUM2LONG(duration) * 1000L;
612
- }
613
-
614
- else if (RB_FLOAT_TYPE_P(duration)) {
615
- double value = RFLOAT_VALUE(duration);
616
-
617
- return value * 1000;
618
- }
619
-
620
- rb_raise(rb_eRuntimeError, "unable to convert timeout");
621
- }
622
-
623
- static
624
- int timeout_nonblocking(int timeout) {
625
- return timeout == 0;
626
- }
627
- #endif
628
602
 
629
603
  struct select_arguments {
630
604
  struct IO_Event_Selector_EPoll *data;
@@ -632,24 +606,52 @@ struct select_arguments {
632
606
  int count;
633
607
  struct epoll_event events[EPOLL_MAX_EVENTS];
634
608
 
635
- #if defined(HAVE_EPOLL_PWAIT2)
636
609
  struct timespec * timeout;
637
610
  struct timespec storage;
638
- #else
639
- int timeout;
640
- #endif
641
611
  };
642
612
 
613
+ static int make_timeout_ms(struct timespec * timeout) {
614
+ if (timeout == NULL) {
615
+ return -1;
616
+ }
617
+
618
+ if (timeout_nonblocking(timeout)) {
619
+ return 0;
620
+ }
621
+
622
+ return (timeout->tv_sec * 1000) + (timeout->tv_nsec / 1000000);
623
+ }
624
+
625
+ static
626
+ int enosys_error(int result) {
627
+ if (result == -1) {
628
+ return errno == ENOSYS;
629
+ }
630
+
631
+ return 0;
632
+ }
633
+
643
634
  static
644
635
  void * select_internal(void *_arguments) {
645
636
  struct select_arguments * arguments = (struct select_arguments *)_arguments;
646
637
 
647
638
  #if defined(HAVE_EPOLL_PWAIT2)
648
639
  arguments->count = epoll_pwait2(arguments->data->descriptor, arguments->events, EPOLL_MAX_EVENTS, arguments->timeout, NULL);
649
- #else
650
- arguments->count = epoll_wait(arguments->data->descriptor, arguments->events, EPOLL_MAX_EVENTS, arguments->timeout);
640
+
641
+ // Comment out the above line and enable the below lines to test ENOSYS code path.
642
+ // arguments->count = -1;
643
+ // errno = ENOSYS;
644
+
645
+ if (!enosys_error(arguments->count)) {
646
+ return NULL;
647
+ }
648
+ else {
649
+ // Fall through and execute epoll_wait fallback.
650
+ }
651
651
  #endif
652
652
 
653
+ arguments->count = epoll_wait(arguments->data->descriptor, arguments->events, EPOLL_MAX_EVENTS, make_timeout_ms(arguments->timeout));
654
+
653
655
  return NULL;
654
656
  }
655
657
 
@@ -689,20 +691,14 @@ VALUE IO_Event_Selector_EPoll_select(VALUE self, VALUE duration) {
689
691
 
690
692
  struct select_arguments arguments = {
691
693
  .data = data,
692
- #if defined(HAVE_EPOLL_PWAIT2)
693
694
  .storage = {
694
695
  .tv_sec = 0,
695
696
  .tv_nsec = 0
696
- }
697
- #else
698
- .timeout = 0
699
- #endif
697
+ },
700
698
  };
701
-
702
- #if defined(HAVE_EPOLL_PWAIT2)
699
+
703
700
  arguments.timeout = &arguments.storage;
704
- #endif
705
-
701
+
706
702
  // Process any currently pending events:
707
703
  select_internal_with_gvl(&arguments);
708
704
 
@@ -712,11 +708,7 @@ VALUE IO_Event_Selector_EPoll_select(VALUE self, VALUE duration) {
712
708
  // 3. There are no items in the ready list,
713
709
  // then we can perform a blocking select.
714
710
  if (!ready && !arguments.count && !data->backend.ready) {
715
- #if defined(HAVE_EPOLL_PWAIT2)
716
711
  arguments.timeout = make_timeout(duration, &arguments.storage);
717
- #else
718
- arguments.timeout = make_timeout(duration);
719
- #endif
720
712
 
721
713
  if (!timeout_nonblocking(arguments.timeout)) {
722
714
  // Wait for events to occur
@@ -5,6 +5,6 @@
5
5
 
6
6
  class IO
7
7
  module Event
8
- VERSION = "1.2.0"
8
+ VERSION = "1.2.1"
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.2.0
4
+ version: 1.2.1
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-04-30 00:00:00.000000000 Z
44
+ date: 2023-05-13 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.10
153
+ rubygems_version: 3.4.7
154
154
  signing_key:
155
155
  specification_version: 4
156
156
  summary: An event loop.
metadata.gz.sig CHANGED
Binary file