event 0.9.1 → 0.9.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/event/debug/selector.rb +140 -0
- data/lib/event/version.rb +1 -1
- metadata +2 -2
- data/lib/event/debug.rb +0 -126
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9fab46d1f87926ce1c2c93877e6ca031b5946477479f3801b19fa099267f09ca
|
4
|
+
data.tar.gz: 7b04c272e7032227ddee671d1b4341674bd19fd8d3ee4fa87808d331973c4b71
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5b5f1c414836b039caad30b772523aedd8d8cd975d482e0ccddddea12b6c0cb931c91955ff2ca60b90cf3346cfc392db0c41df923f1f8404866d6b8c7270d43a
|
7
|
+
data.tar.gz: c0352b81e5fdfed6c90c2cbb82b4ecc9ba2395dce98e604777be512b68938a67855644f73c0ef6956a02b8533af744d642bc99cf1785d698af0b4692bcd60511
|
@@ -0,0 +1,140 @@
|
|
1
|
+
# Copyright, 2021, by Samuel G. D. Williams. <http://www.codeotaku.com>
|
2
|
+
#
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
# of this software and associated documentation files (the "Software"), to deal
|
5
|
+
# in the Software without restriction, including without limitation the rights
|
6
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
# copies of the Software, and to permit persons to whom the Software is
|
8
|
+
# furnished to do so, subject to the following conditions:
|
9
|
+
#
|
10
|
+
# The above copyright notice and this permission notice shall be included in
|
11
|
+
# all copies or substantial portions of the Software.
|
12
|
+
#
|
13
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
+
# THE SOFTWARE.
|
20
|
+
|
21
|
+
require "event/version"
|
22
|
+
|
23
|
+
module Event
|
24
|
+
module Debug
|
25
|
+
class Selector
|
26
|
+
def initialize(selector)
|
27
|
+
@selector = selector
|
28
|
+
|
29
|
+
@readable = {}
|
30
|
+
@writable = {}
|
31
|
+
@priority = {}
|
32
|
+
end
|
33
|
+
|
34
|
+
def close
|
35
|
+
if @selector.nil?
|
36
|
+
raise "Selector already closed!"
|
37
|
+
end
|
38
|
+
|
39
|
+
@selector.close
|
40
|
+
@selector = nil
|
41
|
+
end
|
42
|
+
|
43
|
+
def transfer(fiber, *arguments)
|
44
|
+
@selector.transfer(fiber, *arguments)
|
45
|
+
end
|
46
|
+
|
47
|
+
def transfer(*arguments)
|
48
|
+
@selector.transfer(*arguments)
|
49
|
+
end
|
50
|
+
|
51
|
+
def resume(*arguments)
|
52
|
+
@selector.resume(*arguments)
|
53
|
+
end
|
54
|
+
|
55
|
+
def yield
|
56
|
+
@selector.yield
|
57
|
+
end
|
58
|
+
|
59
|
+
def push(fiber)
|
60
|
+
@selector.push(fiber)
|
61
|
+
end
|
62
|
+
|
63
|
+
def raise(fiber, *arguments)
|
64
|
+
@selector.raise(fiber, *arguments)
|
65
|
+
end
|
66
|
+
|
67
|
+
def ready?
|
68
|
+
@selector.ready?
|
69
|
+
end
|
70
|
+
|
71
|
+
def process_wait(*arguments)
|
72
|
+
@selector.process_wait(*arguments)
|
73
|
+
end
|
74
|
+
|
75
|
+
def io_wait(fiber, io, events)
|
76
|
+
register_readable(fiber, io, events)
|
77
|
+
end
|
78
|
+
|
79
|
+
def select(duration = nil)
|
80
|
+
@selector.select(duration)
|
81
|
+
end
|
82
|
+
|
83
|
+
private
|
84
|
+
|
85
|
+
def register_readable(fiber, io, events)
|
86
|
+
if (events & READABLE) > 0
|
87
|
+
if @readable.key?(io)
|
88
|
+
raise "Cannot wait for #{io} to become readable from multiple fibers."
|
89
|
+
end
|
90
|
+
|
91
|
+
begin
|
92
|
+
@readable[io] = fiber
|
93
|
+
|
94
|
+
register_writable(fiber, io, events)
|
95
|
+
ensure
|
96
|
+
@readable.delete(io)
|
97
|
+
end
|
98
|
+
else
|
99
|
+
register_writable(fiber, io, events)
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
def register_writable(fiber, io, events)
|
104
|
+
if (events & WRITABLE) > 0
|
105
|
+
if @writable.key?(io)
|
106
|
+
raise "Cannot wait for #{io} to become writable from multiple fibers."
|
107
|
+
end
|
108
|
+
|
109
|
+
begin
|
110
|
+
@writable[io] = fiber
|
111
|
+
|
112
|
+
register_priority(fiber, io, events)
|
113
|
+
ensure
|
114
|
+
@writable.delete(io)
|
115
|
+
end
|
116
|
+
else
|
117
|
+
register_priority(fiber, io, events)
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
def register_priority(fiber, io, events)
|
122
|
+
if (events & PRIORITY) > 0
|
123
|
+
if @priority.key?(io)
|
124
|
+
raise "Cannot wait for #{io} to become priority from multiple fibers."
|
125
|
+
end
|
126
|
+
|
127
|
+
begin
|
128
|
+
@priority[io] = fiber
|
129
|
+
|
130
|
+
@selector.io_wait(fiber, io, events)
|
131
|
+
ensure
|
132
|
+
@priority.delete(io)
|
133
|
+
end
|
134
|
+
else
|
135
|
+
@selector.io_wait(fiber, io, events)
|
136
|
+
end
|
137
|
+
end
|
138
|
+
end
|
139
|
+
end
|
140
|
+
end
|
data/lib/event/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: event
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Samuel Williams
|
@@ -86,7 +86,7 @@ files:
|
|
86
86
|
- ext/event/selector/uring.c
|
87
87
|
- ext/event/selector/uring.h
|
88
88
|
- lib/event.rb
|
89
|
-
- lib/event/debug.rb
|
89
|
+
- lib/event/debug/selector.rb
|
90
90
|
- lib/event/selector.rb
|
91
91
|
- lib/event/selector/select.rb
|
92
92
|
- lib/event/version.rb
|
data/lib/event/debug.rb
DELETED
@@ -1,126 +0,0 @@
|
|
1
|
-
# Copyright, 2021, by Samuel G. D. Williams. <http://www.codeotaku.com>
|
2
|
-
#
|
3
|
-
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
-
# of this software and associated documentation files (the "Software"), to deal
|
5
|
-
# in the Software without restriction, including without limitation the rights
|
6
|
-
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
-
# copies of the Software, and to permit persons to whom the Software is
|
8
|
-
# furnished to do so, subject to the following conditions:
|
9
|
-
#
|
10
|
-
# The above copyright notice and this permission notice shall be included in
|
11
|
-
# all copies or substantial portions of the Software.
|
12
|
-
#
|
13
|
-
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
-
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
-
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
-
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
-
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
-
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
-
# THE SOFTWARE.
|
20
|
-
|
21
|
-
require "event/version"
|
22
|
-
|
23
|
-
module Event
|
24
|
-
class Debug
|
25
|
-
def initialize(selector)
|
26
|
-
@selector = selector
|
27
|
-
|
28
|
-
@readable = {}
|
29
|
-
@writable = {}
|
30
|
-
@priority = {}
|
31
|
-
end
|
32
|
-
|
33
|
-
def close
|
34
|
-
if @selector.nil?
|
35
|
-
raise "Selector already closed!"
|
36
|
-
end
|
37
|
-
|
38
|
-
@selector.close
|
39
|
-
@selector = nil
|
40
|
-
end
|
41
|
-
|
42
|
-
def transfer(fiber, *arguments)
|
43
|
-
@selector.transfer(fiber, *arguments)
|
44
|
-
end
|
45
|
-
|
46
|
-
def yield
|
47
|
-
@selector.yield
|
48
|
-
end
|
49
|
-
|
50
|
-
def push(fiber)
|
51
|
-
@selector.push(fiber)
|
52
|
-
end
|
53
|
-
|
54
|
-
def raise(fiber, *arguments)
|
55
|
-
@selector.raise(fiber, *arguments)
|
56
|
-
end
|
57
|
-
|
58
|
-
def ready?
|
59
|
-
@selector.ready?
|
60
|
-
end
|
61
|
-
|
62
|
-
def io_wait(fiber, io, events)
|
63
|
-
register_readable(fiber, io, events)
|
64
|
-
end
|
65
|
-
|
66
|
-
def select(duration = nil)
|
67
|
-
@selector.select(duration)
|
68
|
-
end
|
69
|
-
|
70
|
-
private
|
71
|
-
|
72
|
-
def register_readable(fiber, io, events)
|
73
|
-
if (events & READABLE) > 0
|
74
|
-
if @readable.key?(io)
|
75
|
-
raise "Cannot wait for #{io} to become readable from multiple fibers."
|
76
|
-
end
|
77
|
-
|
78
|
-
begin
|
79
|
-
@readable[io] = fiber
|
80
|
-
|
81
|
-
register_writable(fiber, io, events)
|
82
|
-
ensure
|
83
|
-
@readable.delete(io)
|
84
|
-
end
|
85
|
-
else
|
86
|
-
register_writable(fiber, io, events)
|
87
|
-
end
|
88
|
-
end
|
89
|
-
|
90
|
-
def register_writable(fiber, io, events)
|
91
|
-
if (events & WRITABLE) > 0
|
92
|
-
if @writable.key?(io)
|
93
|
-
raise "Cannot wait for #{io} to become writable from multiple fibers."
|
94
|
-
end
|
95
|
-
|
96
|
-
begin
|
97
|
-
@writable[io] = fiber
|
98
|
-
|
99
|
-
register_priority(fiber, io, events)
|
100
|
-
ensure
|
101
|
-
@writable.delete(io)
|
102
|
-
end
|
103
|
-
else
|
104
|
-
register_priority(fiber, io, events)
|
105
|
-
end
|
106
|
-
end
|
107
|
-
|
108
|
-
def register_priority(fiber, io, events)
|
109
|
-
if (events & PRIORITY) > 0
|
110
|
-
if @priority.key?(io)
|
111
|
-
raise "Cannot wait for #{io} to become priority from multiple fibers."
|
112
|
-
end
|
113
|
-
|
114
|
-
begin
|
115
|
-
@priority[io] = fiber
|
116
|
-
|
117
|
-
@selector.io_wait(fiber, io, events)
|
118
|
-
ensure
|
119
|
-
@priority.delete(io)
|
120
|
-
end
|
121
|
-
else
|
122
|
-
@selector.io_wait(fiber, io, events)
|
123
|
-
end
|
124
|
-
end
|
125
|
-
end
|
126
|
-
end
|