polyphony 0.51.0 → 0.52.0
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 +4 -4
- data/.github/workflows/test.yml +1 -1
- data/CHANGELOG.md +10 -0
- data/Gemfile.lock +5 -68
- data/TODO.md +6 -3
- data/examples/core/forking.rb +2 -2
- data/ext/polyphony/backend_common.h +29 -6
- data/ext/polyphony/backend_io_uring.c +49 -5
- data/ext/polyphony/backend_libev.c +145 -11
- data/ext/polyphony/event.c +1 -1
- data/ext/polyphony/extconf.rb +7 -2
- data/ext/polyphony/polyphony.c +94 -0
- data/ext/polyphony/polyphony.h +28 -2
- data/ext/polyphony/queue.c +1 -1
- data/ext/polyphony/runqueue.c +1 -1
- data/lib/polyphony/adapters/irb.rb +1 -1
- data/lib/polyphony/adapters/mysql2.rb +1 -1
- data/lib/polyphony/adapters/postgres.rb +5 -5
- data/lib/polyphony/adapters/process.rb +2 -2
- data/lib/polyphony/core/global_api.rb +5 -5
- data/lib/polyphony/core/sync.rb +1 -1
- data/lib/polyphony/core/throttler.rb +1 -1
- data/lib/polyphony/core/timer.rb +2 -2
- data/lib/polyphony/extensions/core.rb +1 -1
- data/lib/polyphony/extensions/io.rb +12 -25
- data/lib/polyphony/extensions/openssl.rb +6 -6
- data/lib/polyphony/extensions/socket.rb +35 -47
- data/lib/polyphony/version.rb +1 -1
- data/polyphony.gemspec +5 -5
- data/test/helper.rb +1 -1
- data/test/stress.rb +2 -0
- data/test/test_backend.rb +33 -5
- data/test/test_global_api.rb +2 -2
- data/test/test_io.rb +33 -2
- data/test/test_kernel.rb +1 -1
- data/test/test_signal.rb +1 -1
- data/test/test_socket.rb +27 -0
- data/test/test_timer.rb +1 -1
- metadata +4 -60
@@ -7,7 +7,7 @@ module Polyphony
|
|
7
7
|
def watch(cmd = nil, &block)
|
8
8
|
terminated = nil
|
9
9
|
pid = cmd ? Kernel.spawn(cmd) : Polyphony.fork(&block)
|
10
|
-
|
10
|
+
Polyphony.backend_waitpid(pid)
|
11
11
|
terminated = true
|
12
12
|
ensure
|
13
13
|
kill_process(pid) unless terminated || pid.nil?
|
@@ -23,7 +23,7 @@ module Polyphony
|
|
23
23
|
|
24
24
|
def kill_and_await(sig, pid)
|
25
25
|
::Process.kill(sig, pid)
|
26
|
-
|
26
|
+
Polyphony.backend_waitpid(pid)
|
27
27
|
rescue Errno::ESRCH
|
28
28
|
# process doesn't exist
|
29
29
|
end
|
@@ -21,7 +21,7 @@ module Polyphony
|
|
21
21
|
elsif block.arity > 0
|
22
22
|
cancel_after_with_block(Fiber.current, interval, with_exception, &block)
|
23
23
|
else
|
24
|
-
|
24
|
+
Polyphony.backend_timeout(interval, with_exception, &block)
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
@@ -82,7 +82,7 @@ module Polyphony
|
|
82
82
|
end
|
83
83
|
|
84
84
|
def every(interval, &block)
|
85
|
-
|
85
|
+
Polyphony.backend_timer_loop(interval, &block)
|
86
86
|
end
|
87
87
|
|
88
88
|
def move_on_after(interval, with_value: nil, &block)
|
@@ -91,7 +91,7 @@ module Polyphony
|
|
91
91
|
elsif block.arity > 0
|
92
92
|
move_on_after_with_block(Fiber.current, interval, with_value, &block)
|
93
93
|
else
|
94
|
-
|
94
|
+
Polyphony.backend_timeout(interval, nil, with_value, &block)
|
95
95
|
end
|
96
96
|
end
|
97
97
|
|
@@ -129,11 +129,11 @@ module Polyphony
|
|
129
129
|
def sleep(duration = nil)
|
130
130
|
return sleep_forever unless duration
|
131
131
|
|
132
|
-
|
132
|
+
Polyphony.backend_sleep duration
|
133
133
|
end
|
134
134
|
|
135
135
|
def sleep_forever
|
136
|
-
|
136
|
+
Polyphony.backend_wait_event(true)
|
137
137
|
end
|
138
138
|
|
139
139
|
def throttled_loop(rate = nil, **opts, &block)
|
data/lib/polyphony/core/sync.rb
CHANGED
data/lib/polyphony/core/timer.rb
CHANGED
@@ -18,7 +18,7 @@ module Polyphony
|
|
18
18
|
interval: duration,
|
19
19
|
target_stamp: now + duration
|
20
20
|
}
|
21
|
-
|
21
|
+
Polyphony.backend_wait_event(true)
|
22
22
|
ensure
|
23
23
|
@timeouts.delete(fiber)
|
24
24
|
end
|
@@ -38,7 +38,7 @@ module Polyphony
|
|
38
38
|
recurring: true
|
39
39
|
}
|
40
40
|
while true
|
41
|
-
|
41
|
+
Polyphony.backend_wait_event(true)
|
42
42
|
yield
|
43
43
|
end
|
44
44
|
ensure
|
@@ -55,7 +55,7 @@ module ::Process
|
|
55
55
|
class << self
|
56
56
|
alias_method :orig_detach, :detach
|
57
57
|
def detach(pid)
|
58
|
-
fiber = spin {
|
58
|
+
fiber = spin { Polyphony.backend_waitpid(pid) }
|
59
59
|
fiber.define_singleton_method(:pid) { pid }
|
60
60
|
fiber
|
61
61
|
end
|
@@ -101,7 +101,7 @@ class ::IO
|
|
101
101
|
return @read_buffer.slice!(0) if @read_buffer && !@read_buffer.empty?
|
102
102
|
|
103
103
|
@read_buffer ||= +''
|
104
|
-
|
104
|
+
Polyphony.backend_read(self, @read_buffer, 8192, false)
|
105
105
|
return @read_buffer.slice!(0) if !@read_buffer.empty?
|
106
106
|
|
107
107
|
nil
|
@@ -110,7 +110,7 @@ class ::IO
|
|
110
110
|
alias_method :orig_read, :read
|
111
111
|
def read(len = nil)
|
112
112
|
@read_buffer ||= +''
|
113
|
-
result =
|
113
|
+
result = Polyphony.backend_read(self, @read_buffer, len, true)
|
114
114
|
return nil unless result
|
115
115
|
|
116
116
|
already_read = @read_buffer
|
@@ -120,7 +120,7 @@ class ::IO
|
|
120
120
|
|
121
121
|
alias_method :orig_readpartial, :read
|
122
122
|
def readpartial(len, str = +'')
|
123
|
-
result =
|
123
|
+
result = Polyphony.backend_read(self, str, len, false)
|
124
124
|
raise EOFError unless result
|
125
125
|
|
126
126
|
result
|
@@ -128,12 +128,12 @@ class ::IO
|
|
128
128
|
|
129
129
|
alias_method :orig_write, :write
|
130
130
|
def write(str, *args)
|
131
|
-
|
131
|
+
Polyphony.backend_write(self, str, *args)
|
132
132
|
end
|
133
133
|
|
134
134
|
alias_method :orig_write_chevron, :<<
|
135
135
|
def <<(str)
|
136
|
-
|
136
|
+
Polyphony.backend_write(self, str)
|
137
137
|
self
|
138
138
|
end
|
139
139
|
|
@@ -217,34 +217,21 @@ class ::IO
|
|
217
217
|
end
|
218
218
|
|
219
219
|
def read_loop(&block)
|
220
|
-
|
220
|
+
Polyphony.backend_read_loop(self, &block)
|
221
221
|
end
|
222
222
|
|
223
|
-
def feed_loop(receiver, method, &block)
|
224
|
-
|
223
|
+
def feed_loop(receiver, method = :call, &block)
|
224
|
+
Polyphony.backend_feed_loop(self, receiver, method, &block)
|
225
225
|
end
|
226
226
|
|
227
|
-
# alias_method :orig_read, :read
|
228
|
-
# def read(length = nil, outbuf = nil)
|
229
|
-
# if length
|
230
|
-
# return outbuf ? readpartial(length) : readpartial(length, outbuf)
|
231
|
-
# end
|
232
|
-
|
233
|
-
# until eof?
|
234
|
-
# outbuf ||= +''
|
235
|
-
# outbuf << readpartial(8192)
|
236
|
-
# end
|
237
|
-
# outbuf
|
238
|
-
# end
|
239
|
-
|
240
227
|
def wait_readable(timeout = nil)
|
241
228
|
if timeout
|
242
229
|
move_on_after(timeout) do
|
243
|
-
|
230
|
+
Polyphony.backend_wait_io(self, false)
|
244
231
|
self
|
245
232
|
end
|
246
233
|
else
|
247
|
-
|
234
|
+
Polyphony.backend_wait_io(self, false)
|
248
235
|
self
|
249
236
|
end
|
250
237
|
end
|
@@ -252,11 +239,11 @@ class ::IO
|
|
252
239
|
def wait_writable(timeout = nil)
|
253
240
|
if timeout
|
254
241
|
move_on_after(timeout) do
|
255
|
-
|
242
|
+
Polyphony.backend_wait_io(self, true)
|
256
243
|
self
|
257
244
|
end
|
258
245
|
else
|
259
|
-
|
246
|
+
Polyphony.backend_wait_io(self, true)
|
260
247
|
self
|
261
248
|
end
|
262
249
|
end
|
@@ -28,8 +28,8 @@ class ::OpenSSL::SSL::SSLSocket
|
|
28
28
|
while true
|
29
29
|
result = accept_nonblock(exception: false)
|
30
30
|
case result
|
31
|
-
when :wait_readable then
|
32
|
-
when :wait_writable then
|
31
|
+
when :wait_readable then Polyphony.backend_wait_io(io, false)
|
32
|
+
when :wait_writable then Polyphony.backend_wait_io(io, true)
|
33
33
|
else
|
34
34
|
return result
|
35
35
|
end
|
@@ -46,8 +46,8 @@ class ::OpenSSL::SSL::SSLSocket
|
|
46
46
|
def sysread(maxlen, buf = +'')
|
47
47
|
while true
|
48
48
|
case (result = read_nonblock(maxlen, buf, exception: false))
|
49
|
-
when :wait_readable then
|
50
|
-
when :wait_writable then
|
49
|
+
when :wait_readable then Polyphony.backend_wait_io(io, false)
|
50
|
+
when :wait_writable then Polyphony.backend_wait_io(io, true)
|
51
51
|
else return result
|
52
52
|
end
|
53
53
|
end
|
@@ -57,8 +57,8 @@ class ::OpenSSL::SSL::SSLSocket
|
|
57
57
|
def syswrite(buf)
|
58
58
|
while true
|
59
59
|
case (result = write_nonblock(buf, exception: false))
|
60
|
-
when :wait_readable then
|
61
|
-
when :wait_writable then
|
60
|
+
when :wait_readable then Polyphony.backend_wait_io(io, false)
|
61
|
+
when :wait_writable then Polyphony.backend_wait_io(io, true)
|
62
62
|
else
|
63
63
|
return result
|
64
64
|
end
|
@@ -8,31 +8,31 @@ require_relative '../core/thread_pool'
|
|
8
8
|
# Socket overrides (eventually rewritten in C)
|
9
9
|
class ::Socket
|
10
10
|
def accept
|
11
|
-
|
11
|
+
Polyphony.backend_accept(self, TCPSocket)
|
12
12
|
end
|
13
13
|
|
14
14
|
def accept_loop(&block)
|
15
|
-
|
15
|
+
Polyphony.backend_accept_loop(self, TCPSocket, &block)
|
16
16
|
end
|
17
17
|
|
18
18
|
NO_EXCEPTION = { exception: false }.freeze
|
19
19
|
|
20
20
|
def connect(addr)
|
21
21
|
addr = Addrinfo.new(addr) if addr.is_a?(String)
|
22
|
-
|
22
|
+
Polyphony.backend_connect(self, addr.ip_address, addr.ip_port)
|
23
23
|
end
|
24
24
|
|
25
25
|
def recv(maxlen, flags = 0, outbuf = nil)
|
26
|
-
|
26
|
+
Polyphony.backend_recv(self, outbuf || +'', maxlen)
|
27
27
|
end
|
28
28
|
|
29
29
|
def recv_loop(&block)
|
30
|
-
|
30
|
+
Polyphony.backend_recv_loop(self, &block)
|
31
31
|
end
|
32
32
|
alias_method :read_loop, :recv_loop
|
33
33
|
|
34
|
-
def feed_loop(receiver, method, &block)
|
35
|
-
|
34
|
+
def feed_loop(receiver, method = :call, &block)
|
35
|
+
Polyphony.backend_recv_feed_loop(self, receiver, method, &block)
|
36
36
|
end
|
37
37
|
|
38
38
|
def recvfrom(maxlen, flags = 0)
|
@@ -41,28 +41,24 @@ class ::Socket
|
|
41
41
|
result = recvfrom_nonblock(maxlen, flags, @read_buffer, **NO_EXCEPTION)
|
42
42
|
case result
|
43
43
|
when nil then raise IOError
|
44
|
-
when :wait_readable then
|
44
|
+
when :wait_readable then Polyphony.backend_wait_io(self, false)
|
45
45
|
else
|
46
46
|
return result
|
47
47
|
end
|
48
48
|
end
|
49
49
|
end
|
50
50
|
|
51
|
-
def send(mesg, flags
|
52
|
-
|
51
|
+
def send(mesg, flags)
|
52
|
+
Polyphony.backend_send(self, mesg, flags)
|
53
53
|
end
|
54
54
|
|
55
|
-
def write(
|
56
|
-
|
57
|
-
Thread.current.backend.send(self, str)
|
58
|
-
else
|
59
|
-
Thread.current.backend.send(self, str + args.join)
|
60
|
-
end
|
55
|
+
def write(*args)
|
56
|
+
Polyphony.backend_sendv(self, args, 0)
|
61
57
|
end
|
62
58
|
alias_method :<<, :write
|
63
59
|
|
64
60
|
def readpartial(maxlen, str = +'')
|
65
|
-
|
61
|
+
Polyphony.backend_recv(self, str, maxlen)
|
66
62
|
end
|
67
63
|
|
68
64
|
ZERO_LINGER = [0, 0].pack('ii').freeze
|
@@ -142,34 +138,30 @@ class ::TCPSocket
|
|
142
138
|
end
|
143
139
|
|
144
140
|
def recv(maxlen, flags = 0, outbuf = nil)
|
145
|
-
|
141
|
+
Polyphony.backend_recv(self, outbuf || +'', maxlen)
|
146
142
|
end
|
147
143
|
|
148
144
|
def recv_loop(&block)
|
149
|
-
|
145
|
+
Polyphony.backend_recv_loop(self, &block)
|
150
146
|
end
|
151
147
|
alias_method :read_loop, :recv_loop
|
152
148
|
|
153
|
-
def feed_loop(receiver, method, &block)
|
154
|
-
|
149
|
+
def feed_loop(receiver, method = :call, &block)
|
150
|
+
Polyphony.backend_recv_feed_loop(self, receiver, method, &block)
|
155
151
|
end
|
156
152
|
|
157
|
-
def send(mesg, flags
|
158
|
-
|
153
|
+
def send(mesg, flags)
|
154
|
+
Polyphony.backend_send(self, mesg, flags)
|
159
155
|
end
|
160
156
|
|
161
|
-
def write(
|
162
|
-
|
163
|
-
Thread.current.backend.send(self, str)
|
164
|
-
else
|
165
|
-
Thread.current.backend.send(self, str + args.join)
|
166
|
-
end
|
157
|
+
def write(*args)
|
158
|
+
Polyphony.backend_sendv(self, args, 0)
|
167
159
|
end
|
168
160
|
alias_method :<<, :write
|
169
161
|
|
170
162
|
def readpartial(maxlen, str = nil)
|
171
163
|
@read_buffer ||= +''
|
172
|
-
result =
|
164
|
+
result = Polyphony.backend_recv(self, @read_buffer, maxlen)
|
173
165
|
raise EOFError unless result
|
174
166
|
|
175
167
|
if str
|
@@ -200,12 +192,12 @@ class ::TCPServer
|
|
200
192
|
|
201
193
|
alias_method :orig_accept, :accept
|
202
194
|
def accept
|
203
|
-
|
195
|
+
Polyphony.backend_accept(@io, TCPSocket)
|
204
196
|
# @io.accept
|
205
197
|
end
|
206
198
|
|
207
199
|
def accept_loop(&block)
|
208
|
-
|
200
|
+
Polyphony.backend_accept_loop(@io, TCPSocket, &block)
|
209
201
|
end
|
210
202
|
|
211
203
|
alias_method :orig_close, :close
|
@@ -217,44 +209,40 @@ end
|
|
217
209
|
class ::UNIXServer
|
218
210
|
alias_method :orig_accept, :accept
|
219
211
|
def accept
|
220
|
-
|
212
|
+
Polyphony.backend_accept(self, UNIXSocket)
|
221
213
|
end
|
222
214
|
|
223
215
|
def accept_loop(&block)
|
224
|
-
|
216
|
+
Polyphony.backend_accept_loop(self, UNIXSocket, &block)
|
225
217
|
end
|
226
218
|
end
|
227
219
|
|
228
220
|
class ::UNIXSocket
|
229
221
|
def recv(maxlen, flags = 0, outbuf = nil)
|
230
|
-
|
222
|
+
Polyphony.backend_recv(self, outbuf || +'', maxlen)
|
231
223
|
end
|
232
224
|
|
233
225
|
def recv_loop(&block)
|
234
|
-
|
226
|
+
Polyphony.backend_recv_loop(self, &block)
|
235
227
|
end
|
236
228
|
alias_method :read_loop, :recv_loop
|
237
229
|
|
238
|
-
def feed_loop(receiver, method, &block)
|
239
|
-
|
230
|
+
def feed_loop(receiver, method = :call, &block)
|
231
|
+
Polyphony.backend_recv_feed_loop(self, receiver, method, &block)
|
240
232
|
end
|
241
233
|
|
242
|
-
def send(mesg, flags
|
243
|
-
|
234
|
+
def send(mesg, flags)
|
235
|
+
Polyphony.backend_send(self, mesg, flags)
|
244
236
|
end
|
245
237
|
|
246
|
-
def write(
|
247
|
-
|
248
|
-
Thread.current.backend.send(self, str)
|
249
|
-
else
|
250
|
-
Thread.current.backend.send(self, str + args.join)
|
251
|
-
end
|
238
|
+
def write(*args)
|
239
|
+
Polyphony.backend_sendv(self, args, 0)
|
252
240
|
end
|
253
241
|
alias_method :<<, :write
|
254
242
|
|
255
243
|
def readpartial(maxlen, str = nil)
|
256
244
|
@read_buffer ||= +''
|
257
|
-
result =
|
245
|
+
result = Polyphony.backend_recv(self, @read_buffer, maxlen)
|
258
246
|
raise EOFError unless result
|
259
247
|
|
260
248
|
if str
|
data/lib/polyphony/version.rb
CHANGED
data/polyphony.gemspec
CHANGED
@@ -22,7 +22,7 @@ Gem::Specification.new do |s|
|
|
22
22
|
s.required_ruby_version = '>= 2.6'
|
23
23
|
|
24
24
|
s.add_development_dependency 'rake-compiler', '1.1.1'
|
25
|
-
s.add_development_dependency 'minitest', '5.
|
25
|
+
s.add_development_dependency 'minitest', '5.14.4'
|
26
26
|
s.add_development_dependency 'minitest-reporters', '1.4.2'
|
27
27
|
s.add_development_dependency 'simplecov', '0.17.1'
|
28
28
|
s.add_development_dependency 'rubocop', '0.85.1'
|
@@ -38,8 +38,8 @@ Gem::Specification.new do |s|
|
|
38
38
|
s.add_development_dependency 'sequel', '5.34.0'
|
39
39
|
s.add_development_dependency 'httparty', '0.17.1'
|
40
40
|
|
41
|
-
s.add_development_dependency 'jekyll', '~>3.8.6'
|
42
|
-
s.add_development_dependency 'jekyll-remote-theme', '~>0.4.1'
|
43
|
-
s.add_development_dependency 'jekyll-seo-tag', '~>2.6.1'
|
44
|
-
s.add_development_dependency 'just-the-docs', '~>0.3.0'
|
41
|
+
# s.add_development_dependency 'jekyll', '~>3.8.6'
|
42
|
+
# s.add_development_dependency 'jekyll-remote-theme', '~>0.4.1'
|
43
|
+
# s.add_development_dependency 'jekyll-seo-tag', '~>2.6.1'
|
44
|
+
# s.add_development_dependency 'just-the-docs', '~>0.3.0'
|
45
45
|
end
|