io-event 1.16.2 → 1.16.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8cc6abcf010ce881e4623a5736241660d1ebf6a84883767d761616ddcb23bf4e
4
- data.tar.gz: 4a438756e87e8feaefaafb40014f36c2b240fbbd837d4581c657eb310cb9b95a
3
+ metadata.gz: 83f9faed054855a0c3a50ab469f315c1345a8af43641ab6c5630d648763fc55d
4
+ data.tar.gz: 78114e047cd897ed0192c262d099a93baea21d0c30ddb70cd57e4efc73a40889
5
5
  SHA512:
6
- metadata.gz: b910e009ff697f179290d916e5914621d25a5478e0f09ac806563a0c3808b30fc28ca652042608e60625830468f37088943559c590112dfadb0d3a48d3b54688
7
- data.tar.gz: c7501e4ef87e5c9744d666e43494b60b2b3c490d9e9cb55b75a87f7de199e1421b49ba0ce5e176cbaf230d6f3b8f838a5745cff81bac6f826328e7665de7a9e9
6
+ metadata.gz: 7cea5251f1c5b93b0235e2aa6aa69c65913e13de847a535eee21343060f744b2a810eb901b15b82bbb3c9979d60a620d4d89dfba349473ab6836e9c420985b9d
7
+ data.tar.gz: c8752f8a0bc9da0ca37ae420364a564c68ad4cb6020124f767677a854c7d81639e9e6daa46040d8fc575e02a7231ff5409d72833b8eb15ec72684b063b5d92d2
checksums.yaml.gz.sig CHANGED
Binary file
data/ext/extconf.rb CHANGED
@@ -55,7 +55,7 @@ have_func("rb_io_descriptor")
55
55
  have_func("&rb_process_status_wait")
56
56
  have_func("rb_fiber_current")
57
57
  have_func("&rb_fiber_raise")
58
- have_func("epoll_pwait2") if enable_config("epoll_pwait2", true)
58
+ have_func("epoll_pwait2(0, 0, 0, 0, 0)", "sys/epoll.h") if enable_config("epoll_pwait2", true)
59
59
 
60
60
  have_header("ruby/io/buffer.h")
61
61
 
@@ -107,6 +107,8 @@ module IO::Event
107
107
 
108
108
  @selector.close
109
109
  @selector = nil
110
+
111
+ @log&.flush
110
112
  end
111
113
 
112
114
  # Transfer from the calling fiber to the selector.
@@ -14,29 +14,34 @@ module IO::Event
14
14
  @selector = selector
15
15
  @input, @output = ::IO.pipe
16
16
 
17
+ @output.sync = true
18
+
17
19
  @fiber = Fiber.new do
18
20
  while true
19
21
  if @selector.io_wait(@fiber, @input, IO::READABLE)
20
22
  @input.read_nonblock(1)
21
23
  end
22
24
  end
25
+ rescue IOError
26
+ # This is expected on shutdown.
23
27
  end
24
28
 
25
29
  @fiber.transfer
26
30
  end
27
31
 
28
- # Send a sigle byte interrupt.
32
+ # Send a single byte interrupt.
29
33
  def signal
30
- @output.write(".")
31
- @output.flush
32
- rescue IOError
33
- # Ignore.
34
+ # This must not block or enter blocking operations or raise an exception.
35
+ # Note that `Scheduler#unblock` defers exceptions, so `IOError` will not be raised by `@output.close` until later.
36
+ @output.write_nonblock(".", exception: false) rescue nil
34
37
  end
35
38
 
36
39
  def close
40
+ # In principle, this should cause the fiber to exit:
37
41
  @input.close
42
+
43
+ # This may cause `signal` to raise an exception:
38
44
  @output.close
39
- # @fiber.raise(::Interrupt)
40
45
  end
41
46
  end
42
47
 
@@ -52,15 +52,19 @@ module IO::Event
52
52
  @waiting = nil
53
53
  end
54
54
 
55
+ # An optional reference to a fiber which can be cleared before it is resumed.
55
56
  Optional = Struct.new(:fiber) do
57
+ # Transfer control to the fiber if it is still available.
56
58
  def transfer(*arguments)
57
59
  fiber&.transfer(*arguments)
58
60
  end
59
61
 
62
+ # @returns [Boolean | Nil] Whether the referenced fiber is still alive.
60
63
  def alive?
61
64
  fiber&.alive?
62
65
  end
63
66
 
67
+ # Clear the referenced fiber.
64
68
  def nullify
65
69
  self.fiber = nil
66
70
  end
@@ -111,7 +115,9 @@ module IO::Event
111
115
  !@ready.empty?
112
116
  end
113
117
 
118
+ # A linked list node used to track fibers waiting for IO events.
114
119
  Waiter = Struct.new(:fiber, :events, :tail) do
120
+ # @returns [Boolean | Nil] Whether the waiting fiber is still alive.
115
121
  def alive?
116
122
  self.fiber&.alive?
117
123
  end
@@ -138,10 +144,12 @@ module IO::Event
138
144
  tail&.dispatch(events, &reactivate)
139
145
  end
140
146
 
147
+ # Clear the waiting fiber so it will not be resumed.
141
148
  def invalidate
142
149
  self.fiber = nil
143
150
  end
144
151
 
152
+ # Iterate over each active waiting fiber and its requested events.
145
153
  def each(&block)
146
154
  if fiber = self.fiber
147
155
  yield fiber, self.events
@@ -3,12 +3,17 @@
3
3
  # Released under the MIT License.
4
4
  # Copyright, 2021-2026, by Samuel Williams.
5
5
 
6
+ require_relative "native"
6
7
  require_relative "selector/select"
7
8
  require_relative "debug/selector"
8
9
 
9
10
  module IO::Event
10
11
  # @namespace
11
12
  module Selector
13
+ selectors = [:URing, :EPoll, :KQueue, :Select]
14
+ BEST = const_get(selectors.find{|name| const_defined?(name)})
15
+ private_constant :BEST
16
+
12
17
  # The default selector implementation, which is chosen based on the environment and available implementations.
13
18
  #
14
19
  # @parameter env [Hash] The environment to read configuration from.
@@ -16,16 +21,8 @@ module IO::Event
16
21
  def self.default(env = ENV)
17
22
  if name = env["IO_EVENT_SELECTOR"]&.to_sym
18
23
  return const_get(name)
19
- end
20
-
21
- if self.const_defined?(:URing)
22
- URing
23
- elsif self.const_defined?(:EPoll)
24
- EPoll
25
- elsif self.const_defined?(:KQueue)
26
- KQueue
27
24
  else
28
- Select
25
+ BEST
29
26
  end
30
27
  end
31
28
 
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  # Released under the MIT License.
4
- # Copyright, 2024-2025, by Samuel Williams.
4
+ # Copyright, 2024-2026, by Samuel Williams.
5
5
 
6
6
  require_relative "priority_heap"
7
7
 
@@ -7,6 +7,6 @@
7
7
  class IO
8
8
  # @namespace
9
9
  module Event
10
- VERSION = "1.16.2"
10
+ VERSION = "1.16.4"
11
11
  end
12
12
  end
data/readme.md CHANGED
@@ -18,6 +18,14 @@ Please see the [project documentation](https://socketry.github.io/io-event/) for
18
18
 
19
19
  Please see the [project releases](https://socketry.github.io/io-event/releases/index) for all releases.
20
20
 
21
+ ### v1.16.4
22
+
23
+ - Correctly implement `Interrupt#signal` so that it is robust enough to be called by `Scheduler#unblock`.
24
+
25
+ ### v1.16.3
26
+
27
+ - Handle `IOError` raised while shutting down the pure Ruby interrupt pipe, so `IO::Event::Interrupt#close` does not leak expected shutdown errors from the interrupt fiber.
28
+
21
29
  ### v1.16.2
22
30
 
23
31
  - Improve timer heap performance by batching scheduled timer insertion, compacting cancelled timers during flush, and avoiding unnecessary heap rebuilds for small incremental inserts.
@@ -56,14 +64,6 @@ Please see the [project releases](https://socketry.github.io/io-event/releases/i
56
64
 
57
65
  - [Enhanced `IO::Event::PriorityHeap` with deletion and bulk insertion methods](https://socketry.github.io/io-event/releases/index#enhanced-io::event::priorityheap-with-deletion-and-bulk-insertion-methods)
58
66
 
59
- ### v1.11.2
60
-
61
- - Fix Windows build.
62
-
63
- ### v1.11.1
64
-
65
- - Fix `read_nonblock` when using the `URing` selector, which was not handling zero-length reads correctly. This allows reading available data without blocking.
66
-
67
67
  ## Contributing
68
68
 
69
69
  We welcome contributions to this project.
data/releases.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # Releases
2
2
 
3
+ ## v1.16.4
4
+
5
+ - Correctly implement `Interrupt#signal` so that it is robust enough to be called by `Scheduler#unblock`.
6
+
7
+ ## v1.16.3
8
+
9
+ - Handle `IOError` raised while shutting down the pure Ruby interrupt pipe, so `IO::Event::Interrupt#close` does not leak expected shutdown errors from the interrupt fiber.
10
+
3
11
  ## v1.16.2
4
12
 
5
13
  - Improve timer heap performance by batching scheduled timer insertion, compacting cancelled timers during flush, and avoiding unnecessary heap rebuilds for small incremental inserts.
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,17 +1,17 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: io-event
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.16.2
4
+ version: 1.16.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
8
8
  - Math Ieu
9
9
  - Wander Hillen
10
10
  - Jean Boussier
11
+ - Tavian Barnes
11
12
  - Benoit Daloze
12
13
  - Bruno Sutic
13
14
  - Shizuo Fujita
14
- - Tavian Barnes
15
15
  - Alex Matchneer
16
16
  - Anthony Ross
17
17
  - Delton Ding
metadata.gz.sig CHANGED
Binary file