polyphony 0.49.2 → 0.53.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 +34 -0
- data/Gemfile.lock +7 -68
- data/TODO.md +37 -3
- data/examples/core/forking.rb +2 -2
- data/examples/core/nested.rb +21 -0
- data/examples/core/suspend.rb +13 -0
- data/examples/core/terminate_main_fiber.rb +12 -0
- data/examples/io/echo_server.rb +1 -0
- data/examples/io/tcp_proxy.rb +2 -2
- data/ext/polyphony/backend_common.h +58 -8
- data/ext/polyphony/backend_io_uring.c +223 -41
- data/ext/polyphony/backend_io_uring_context.c +1 -0
- data/ext/polyphony/backend_io_uring_context.h +1 -0
- data/ext/polyphony/backend_libev.c +322 -34
- data/ext/polyphony/event.c +1 -1
- data/ext/polyphony/extconf.rb +9 -2
- data/ext/polyphony/fiber.c +2 -1
- data/ext/polyphony/polyphony.c +102 -0
- data/ext/polyphony/polyphony.h +33 -2
- data/ext/polyphony/polyphony_ext.c +3 -0
- data/ext/polyphony/queue.c +1 -1
- data/ext/polyphony/runqueue.c +7 -1
- data/ext/polyphony/runqueue_ring_buffer.c +9 -0
- data/ext/polyphony/runqueue_ring_buffer.h +1 -0
- data/ext/polyphony/socket_extensions.c +33 -0
- data/ext/polyphony/thread.c +14 -0
- 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 +4 -4
- data/lib/polyphony/core/exceptions.rb +1 -0
- data/lib/polyphony/core/global_api.rb +6 -6
- data/lib/polyphony/core/sync.rb +1 -1
- data/lib/polyphony/core/throttler.rb +1 -1
- data/lib/polyphony/core/timer.rb +63 -20
- data/lib/polyphony/extensions/core.rb +5 -5
- data/lib/polyphony/extensions/fiber.rb +2 -0
- data/lib/polyphony/extensions/io.rb +21 -22
- data/lib/polyphony/extensions/openssl.rb +6 -6
- data/lib/polyphony/extensions/socket.rb +56 -47
- data/lib/polyphony/version.rb +1 -1
- data/polyphony.gemspec +6 -5
- data/test/helper.rb +1 -1
- data/test/stress.rb +2 -0
- data/test/test_backend.rb +69 -5
- data/test/test_fiber.rb +16 -0
- data/test/test_global_api.rb +2 -2
- data/test/test_io.rb +84 -1
- data/test/test_kernel.rb +1 -1
- data/test/test_signal.rb +1 -1
- data/test/test_socket.rb +61 -0
- data/test/test_timer.rb +41 -8
- metadata +22 -60
|
@@ -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
|
|
|
@@ -29,7 +29,7 @@ module Polyphony
|
|
|
29
29
|
spin do
|
|
30
30
|
sleep interval
|
|
31
31
|
exception = cancel_exception(with_exception)
|
|
32
|
-
exception.
|
|
32
|
+
exception.raising_fiber = nil
|
|
33
33
|
fiber.schedule exception
|
|
34
34
|
end
|
|
35
35
|
end
|
|
@@ -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
|
@@ -11,12 +11,45 @@ module Polyphony
|
|
|
11
11
|
def stop
|
|
12
12
|
@fiber.stop
|
|
13
13
|
end
|
|
14
|
+
|
|
15
|
+
def sleep(duration)
|
|
16
|
+
fiber = Fiber.current
|
|
17
|
+
@timeouts[fiber] = {
|
|
18
|
+
interval: duration,
|
|
19
|
+
target_stamp: now + duration
|
|
20
|
+
}
|
|
21
|
+
Polyphony.backend_wait_event(true)
|
|
22
|
+
ensure
|
|
23
|
+
@timeouts.delete(fiber)
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def after(interval, &block)
|
|
27
|
+
spin do
|
|
28
|
+
self.sleep interval
|
|
29
|
+
block.()
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def every(interval)
|
|
34
|
+
fiber = Fiber.current
|
|
35
|
+
@timeouts[fiber] = {
|
|
36
|
+
interval: interval,
|
|
37
|
+
target_stamp: now + interval,
|
|
38
|
+
recurring: true
|
|
39
|
+
}
|
|
40
|
+
while true
|
|
41
|
+
Polyphony.backend_wait_event(true)
|
|
42
|
+
yield
|
|
43
|
+
end
|
|
44
|
+
ensure
|
|
45
|
+
@timeouts.delete(fiber)
|
|
46
|
+
end
|
|
14
47
|
|
|
15
|
-
def cancel_after(
|
|
48
|
+
def cancel_after(interval, with_exception: Polyphony::Cancel)
|
|
16
49
|
fiber = Fiber.current
|
|
17
50
|
@timeouts[fiber] = {
|
|
18
|
-
|
|
19
|
-
target_stamp:
|
|
51
|
+
interval: interval,
|
|
52
|
+
target_stamp: now + interval,
|
|
20
53
|
exception: with_exception
|
|
21
54
|
}
|
|
22
55
|
yield
|
|
@@ -24,12 +57,12 @@ module Polyphony
|
|
|
24
57
|
@timeouts.delete(fiber)
|
|
25
58
|
end
|
|
26
59
|
|
|
27
|
-
def move_on_after(
|
|
60
|
+
def move_on_after(interval, with_value: nil)
|
|
28
61
|
fiber = Fiber.current
|
|
29
62
|
@timeouts[fiber] = {
|
|
30
|
-
|
|
31
|
-
target_stamp:
|
|
32
|
-
|
|
63
|
+
interval: interval,
|
|
64
|
+
target_stamp: now + interval,
|
|
65
|
+
exception: [Polyphony::MoveOn, with_value]
|
|
33
66
|
}
|
|
34
67
|
yield
|
|
35
68
|
rescue Polyphony::MoveOn => e
|
|
@@ -37,36 +70,46 @@ module Polyphony
|
|
|
37
70
|
ensure
|
|
38
71
|
@timeouts.delete(fiber)
|
|
39
72
|
end
|
|
40
|
-
|
|
73
|
+
|
|
41
74
|
def reset
|
|
42
75
|
record = @timeouts[Fiber.current]
|
|
43
76
|
return unless record
|
|
44
77
|
|
|
45
|
-
record[:target_stamp] =
|
|
78
|
+
record[:target_stamp] = now + record[:interval]
|
|
46
79
|
end
|
|
47
|
-
|
|
80
|
+
|
|
48
81
|
private
|
|
49
82
|
|
|
83
|
+
def now
|
|
84
|
+
::Process.clock_gettime(::Process::CLOCK_MONOTONIC)
|
|
85
|
+
end
|
|
86
|
+
|
|
50
87
|
def timeout_exception(record)
|
|
51
88
|
case (exception = record[:exception])
|
|
52
|
-
when
|
|
53
|
-
|
|
54
|
-
when
|
|
55
|
-
|
|
89
|
+
when Array
|
|
90
|
+
exception[0].new(exception[1])
|
|
91
|
+
when Class
|
|
92
|
+
exception.new
|
|
93
|
+
else
|
|
94
|
+
RuntimeError.new(exception)
|
|
56
95
|
end
|
|
57
96
|
end
|
|
58
97
|
|
|
59
98
|
def update
|
|
60
|
-
|
|
61
|
-
|
|
99
|
+
return if @timeouts.empty?
|
|
100
|
+
|
|
62
101
|
@timeouts.each do |fiber, record|
|
|
63
102
|
next if record[:target_stamp] > now
|
|
64
103
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
104
|
+
value = record[:exception] ? timeout_exception(record) : record[:value]
|
|
105
|
+
fiber.schedule value
|
|
106
|
+
|
|
107
|
+
next unless record[:recurring]
|
|
108
|
+
|
|
109
|
+
while record[:target_stamp] <= now
|
|
110
|
+
record[:target_stamp] += record[:interval]
|
|
111
|
+
end
|
|
68
112
|
end
|
|
69
|
-
# elapsed&.each { |f| @timeouts.delete(f) }
|
|
70
113
|
end
|
|
71
114
|
end
|
|
72
115
|
end
|
|
@@ -12,11 +12,11 @@ class ::Exception
|
|
|
12
12
|
attr_accessor :__disable_sanitized_backtrace__
|
|
13
13
|
end
|
|
14
14
|
|
|
15
|
-
attr_accessor :source_fiber, :
|
|
15
|
+
attr_accessor :source_fiber, :raising_fiber
|
|
16
16
|
|
|
17
17
|
alias_method :orig_initialize, :initialize
|
|
18
18
|
def initialize(*args)
|
|
19
|
-
@
|
|
19
|
+
@raising_fiber = Fiber.current
|
|
20
20
|
orig_initialize(*args)
|
|
21
21
|
end
|
|
22
22
|
|
|
@@ -31,10 +31,10 @@ class ::Exception
|
|
|
31
31
|
end
|
|
32
32
|
|
|
33
33
|
def sanitized_backtrace
|
|
34
|
-
return sanitize(orig_backtrace) unless @
|
|
34
|
+
return sanitize(orig_backtrace) unless @raising_fiber
|
|
35
35
|
|
|
36
36
|
backtrace = orig_backtrace || []
|
|
37
|
-
sanitize(backtrace + @
|
|
37
|
+
sanitize(backtrace + @raising_fiber.caller)
|
|
38
38
|
end
|
|
39
39
|
|
|
40
40
|
POLYPHONY_DIR = File.expand_path(File.join(__dir__, '..'))
|
|
@@ -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,30 +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
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
# return outbuf ? readpartial(length) : readpartial(length, outbuf)
|
|
227
|
-
# end
|
|
228
|
-
|
|
229
|
-
# until eof?
|
|
230
|
-
# outbuf ||= +''
|
|
231
|
-
# outbuf << readpartial(8192)
|
|
232
|
-
# end
|
|
233
|
-
# outbuf
|
|
234
|
-
# end
|
|
223
|
+
def feed_loop(receiver, method = :call, &block)
|
|
224
|
+
Polyphony.backend_feed_loop(self, receiver, method, &block)
|
|
225
|
+
end
|
|
235
226
|
|
|
236
227
|
def wait_readable(timeout = nil)
|
|
237
228
|
if timeout
|
|
238
229
|
move_on_after(timeout) do
|
|
239
|
-
|
|
230
|
+
Polyphony.backend_wait_io(self, false)
|
|
240
231
|
self
|
|
241
232
|
end
|
|
242
233
|
else
|
|
243
|
-
|
|
234
|
+
Polyphony.backend_wait_io(self, false)
|
|
244
235
|
self
|
|
245
236
|
end
|
|
246
237
|
end
|
|
@@ -248,12 +239,20 @@ class ::IO
|
|
|
248
239
|
def wait_writable(timeout = nil)
|
|
249
240
|
if timeout
|
|
250
241
|
move_on_after(timeout) do
|
|
251
|
-
|
|
242
|
+
Polyphony.backend_wait_io(self, true)
|
|
252
243
|
self
|
|
253
244
|
end
|
|
254
245
|
else
|
|
255
|
-
|
|
246
|
+
Polyphony.backend_wait_io(self, true)
|
|
256
247
|
self
|
|
257
248
|
end
|
|
258
249
|
end
|
|
250
|
+
|
|
251
|
+
def splice(src, maxlen)
|
|
252
|
+
Polyphony.backend_splice(src, self, maxlen)
|
|
253
|
+
end
|
|
254
|
+
|
|
255
|
+
def splice_to_eof(src, chunksize = 8192)
|
|
256
|
+
Polyphony.backend_splice_to_eof(src, self, chunksize)
|
|
257
|
+
end
|
|
259
258
|
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,57 +8,60 @@ 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 = :call, &block)
|
|
35
|
+
Polyphony.backend_recv_feed_loop(self, receiver, method, &block)
|
|
36
|
+
end
|
|
37
|
+
|
|
34
38
|
def recvfrom(maxlen, flags = 0)
|
|
35
39
|
@read_buffer ||= +''
|
|
36
40
|
while true
|
|
37
41
|
result = recvfrom_nonblock(maxlen, flags, @read_buffer, **NO_EXCEPTION)
|
|
38
42
|
case result
|
|
39
43
|
when nil then raise IOError
|
|
40
|
-
when :wait_readable then
|
|
44
|
+
when :wait_readable then Polyphony.backend_wait_io(self, false)
|
|
41
45
|
else
|
|
42
46
|
return result
|
|
43
47
|
end
|
|
44
48
|
end
|
|
45
49
|
end
|
|
46
50
|
|
|
47
|
-
def send(mesg, flags
|
|
48
|
-
|
|
49
|
-
end
|
|
51
|
+
# def send(mesg, flags)
|
|
52
|
+
# Polyphony.backend_send(self, mesg, flags)
|
|
53
|
+
# end
|
|
50
54
|
|
|
51
|
-
def write(
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
end
|
|
58
|
-
alias_method :<<, :write
|
|
55
|
+
# def write(*args)
|
|
56
|
+
# Polyphony.backend_sendv(self, args, 0)
|
|
57
|
+
# end
|
|
58
|
+
|
|
59
|
+
# def <<(mesg)
|
|
60
|
+
# Polyphony.backend_send(self, mesg, 0)
|
|
61
|
+
# end
|
|
59
62
|
|
|
60
63
|
def readpartial(maxlen, str = +'')
|
|
61
|
-
|
|
64
|
+
Polyphony.backend_recv(self, str, maxlen)
|
|
62
65
|
end
|
|
63
66
|
|
|
64
67
|
ZERO_LINGER = [0, 0].pack('ii').freeze
|
|
@@ -138,30 +141,33 @@ class ::TCPSocket
|
|
|
138
141
|
end
|
|
139
142
|
|
|
140
143
|
def recv(maxlen, flags = 0, outbuf = nil)
|
|
141
|
-
|
|
144
|
+
Polyphony.backend_recv(self, outbuf || +'', maxlen)
|
|
142
145
|
end
|
|
143
146
|
|
|
144
147
|
def recv_loop(&block)
|
|
145
|
-
|
|
148
|
+
Polyphony.backend_recv_loop(self, &block)
|
|
146
149
|
end
|
|
147
150
|
alias_method :read_loop, :recv_loop
|
|
148
151
|
|
|
149
|
-
def
|
|
150
|
-
|
|
152
|
+
def feed_loop(receiver, method = :call, &block)
|
|
153
|
+
Polyphony.backend_recv_feed_loop(self, receiver, method, &block)
|
|
151
154
|
end
|
|
152
155
|
|
|
153
|
-
def
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
end
|
|
160
|
-
|
|
156
|
+
# def send(mesg, flags)
|
|
157
|
+
# Polyphony.backend_send(self, mesg, flags)
|
|
158
|
+
# end
|
|
159
|
+
|
|
160
|
+
# def write(*args)
|
|
161
|
+
# Polyphony.backend_sendv(self, args, 0)
|
|
162
|
+
# end
|
|
163
|
+
|
|
164
|
+
# def <<(mesg)
|
|
165
|
+
# Polyphony.backend_send(self, mesg, 0)
|
|
166
|
+
# end
|
|
161
167
|
|
|
162
168
|
def readpartial(maxlen, str = nil)
|
|
163
169
|
@read_buffer ||= +''
|
|
164
|
-
result =
|
|
170
|
+
result = Polyphony.backend_recv(self, @read_buffer, maxlen)
|
|
165
171
|
raise EOFError unless result
|
|
166
172
|
|
|
167
173
|
if str
|
|
@@ -192,12 +198,12 @@ class ::TCPServer
|
|
|
192
198
|
|
|
193
199
|
alias_method :orig_accept, :accept
|
|
194
200
|
def accept
|
|
195
|
-
|
|
201
|
+
Polyphony.backend_accept(@io, TCPSocket)
|
|
196
202
|
# @io.accept
|
|
197
203
|
end
|
|
198
204
|
|
|
199
205
|
def accept_loop(&block)
|
|
200
|
-
|
|
206
|
+
Polyphony.backend_accept_loop(@io, TCPSocket, &block)
|
|
201
207
|
end
|
|
202
208
|
|
|
203
209
|
alias_method :orig_close, :close
|
|
@@ -209,40 +215,43 @@ end
|
|
|
209
215
|
class ::UNIXServer
|
|
210
216
|
alias_method :orig_accept, :accept
|
|
211
217
|
def accept
|
|
212
|
-
|
|
218
|
+
Polyphony.backend_accept(self, UNIXSocket)
|
|
213
219
|
end
|
|
214
220
|
|
|
215
221
|
def accept_loop(&block)
|
|
216
|
-
|
|
222
|
+
Polyphony.backend_accept_loop(self, UNIXSocket, &block)
|
|
217
223
|
end
|
|
218
224
|
end
|
|
219
225
|
|
|
220
226
|
class ::UNIXSocket
|
|
221
227
|
def recv(maxlen, flags = 0, outbuf = nil)
|
|
222
|
-
|
|
228
|
+
Polyphony.backend_recv(self, outbuf || +'', maxlen)
|
|
223
229
|
end
|
|
224
230
|
|
|
225
231
|
def recv_loop(&block)
|
|
226
|
-
|
|
232
|
+
Polyphony.backend_recv_loop(self, &block)
|
|
227
233
|
end
|
|
228
234
|
alias_method :read_loop, :recv_loop
|
|
229
235
|
|
|
230
|
-
def
|
|
231
|
-
|
|
236
|
+
def feed_loop(receiver, method = :call, &block)
|
|
237
|
+
Polyphony.backend_recv_feed_loop(self, receiver, method, &block)
|
|
232
238
|
end
|
|
233
239
|
|
|
234
|
-
def
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
+
def send(mesg, flags)
|
|
241
|
+
Polyphony.backend_send(self, mesg, flags)
|
|
242
|
+
end
|
|
243
|
+
|
|
244
|
+
def write(*args)
|
|
245
|
+
Polyphony.backend_sendv(self, args, 0)
|
|
246
|
+
end
|
|
247
|
+
|
|
248
|
+
def <<(mesg)
|
|
249
|
+
Polyphony.backend_send(self, mesg, 0)
|
|
240
250
|
end
|
|
241
|
-
alias_method :<<, :write
|
|
242
251
|
|
|
243
252
|
def readpartial(maxlen, str = nil)
|
|
244
253
|
@read_buffer ||= +''
|
|
245
|
-
result =
|
|
254
|
+
result = Polyphony.backend_recv(self, @read_buffer, maxlen)
|
|
246
255
|
raise EOFError unless result
|
|
247
256
|
|
|
248
257
|
if str
|