polyphony 0.17 → 0.19
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +15 -0
- data/Gemfile.lock +11 -3
- data/README.md +18 -18
- data/TODO.md +5 -21
- data/examples/core/channel_echo.rb +3 -3
- data/examples/core/enumerator.rb +1 -1
- data/examples/core/fork.rb +1 -1
- data/examples/core/genserver.rb +1 -1
- data/examples/core/lock.rb +3 -3
- data/examples/core/multiple_spawn.rb +2 -2
- data/examples/core/nested_async.rb +1 -1
- data/examples/core/nested_multiple_spawn.rb +3 -3
- data/examples/core/resource_cancel.rb +1 -1
- data/examples/core/sleep_spawn.rb +2 -2
- data/examples/core/spawn.rb +1 -1
- data/examples/core/spawn_cancel.rb +1 -1
- data/examples/core/spawn_error.rb +4 -4
- data/examples/core/supervisor.rb +1 -1
- data/examples/core/supervisor_with_error.rb +1 -1
- data/examples/core/supervisor_with_manual_move_on.rb +1 -1
- data/examples/core/thread.rb +2 -2
- data/examples/core/thread_cancel.rb +2 -2
- data/examples/core/thread_pool.rb +1 -1
- data/examples/core/throttle.rb +3 -3
- data/examples/core/timeout.rb +10 -0
- data/examples/fs/read.rb +1 -1
- data/examples/http/http_client.rb +1 -1
- data/examples/http/http_get.rb +7 -0
- data/examples/http/http_parse_experiment.rb +118 -0
- data/examples/http/http_proxy.rb +81 -0
- data/examples/http/http_server.rb +15 -4
- data/examples/http/http_server_forked.rb +2 -2
- data/examples/http/http_server_throttled.rb +1 -1
- data/examples/http/http_ws_server.rb +2 -2
- data/examples/http/https_server.rb +5 -1
- data/examples/http/https_wss_server.rb +1 -1
- data/examples/http/rack_server_https_forked.rb +1 -1
- data/examples/interfaces/pg_client.rb +1 -1
- data/examples/interfaces/pg_pool.rb +1 -1
- data/examples/interfaces/redis_channels.rb +5 -5
- data/examples/interfaces/redis_pubsub.rb +2 -2
- data/examples/interfaces/redis_pubsub_perf.rb +3 -3
- data/examples/io/echo_client.rb +2 -2
- data/examples/io/echo_pipe.rb +17 -0
- data/examples/io/echo_server.rb +1 -1
- data/examples/io/echo_server_with_timeout.rb +1 -1
- data/examples/io/httparty.rb +10 -0
- data/examples/io/httparty_multi.rb +29 -0
- data/examples/io/httparty_threaded.rb +25 -0
- data/examples/io/irb.rb +15 -0
- data/examples/io/net-http.rb +15 -0
- data/examples/io/system.rb +1 -1
- data/examples/io/tcpsocket.rb +18 -0
- data/examples/performance/perf_multi_snooze.rb +2 -2
- data/examples/performance/perf_snooze.rb +17 -20
- data/examples/performance/thread-vs-fiber/polyphony_server.rb +1 -1
- data/ext/ev/ev.h +9 -1
- data/ext/ev/ev_ext.c +4 -1
- data/ext/ev/ev_module.c +36 -22
- data/ext/ev/extconf.rb +1 -1
- data/ext/ev/io.c +23 -23
- data/ext/ev/signal.c +1 -1
- data/ext/ev/socket.c +161 -0
- data/lib/polyphony/core/coprocess.rb +1 -1
- data/lib/polyphony/core/fiber_pool.rb +2 -2
- data/lib/polyphony/core/supervisor.rb +2 -18
- data/lib/polyphony/extensions/io.rb +19 -6
- data/lib/polyphony/extensions/kernel.rb +17 -5
- data/lib/polyphony/extensions/socket.rb +40 -1
- data/lib/polyphony/http/agent.rb +56 -25
- data/lib/polyphony/http/http1_adapter.rb +254 -0
- data/lib/polyphony/http/http2_adapter.rb +157 -0
- data/lib/polyphony/http/{http2_request.rb → request.rb} +25 -22
- data/lib/polyphony/http/server.rb +19 -11
- data/lib/polyphony/net.rb +10 -6
- data/lib/polyphony/version.rb +1 -1
- data/polyphony.gemspec +6 -5
- data/test/test_coprocess.rb +9 -9
- data/test/test_core.rb +14 -14
- data/test/test_io.rb +4 -4
- data/test/test_kernel.rb +1 -1
- metadata +48 -23
- data/lib/polyphony/http/http1.rb +0 -124
- data/lib/polyphony/http/http1_request.rb +0 -83
- data/lib/polyphony/http/http2.rb +0 -65
data/lib/polyphony/http/http2.rb
DELETED
@@ -1,65 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
export :call, :upgrade
|
4
|
-
|
5
|
-
require 'http/2'
|
6
|
-
|
7
|
-
Request = import('./http2_request')
|
8
|
-
|
9
|
-
def call(socket, opts, &handler)
|
10
|
-
interface = prepare(socket, handler)
|
11
|
-
client_loop(socket, interface)
|
12
|
-
end
|
13
|
-
|
14
|
-
UPGRADE_MESSAGE = <<~HTTP.gsub("\n", "\r\n")
|
15
|
-
HTTP/1.1 101 Switching Protocols
|
16
|
-
Connection: Upgrade
|
17
|
-
Upgrade: h2c
|
18
|
-
|
19
|
-
HTTP
|
20
|
-
|
21
|
-
def upgrade(socket, handler, request, body)
|
22
|
-
interface = prepare(socket, handler)
|
23
|
-
settings = request['HTTP2-Settings']
|
24
|
-
socket.write(UPGRADE_MESSAGE)
|
25
|
-
interface.upgrade(settings, request, body)
|
26
|
-
client_loop(socket, interface)
|
27
|
-
end
|
28
|
-
|
29
|
-
def prepare(socket, handler)
|
30
|
-
::HTTP2::Server.new.tap do |interface|
|
31
|
-
interface.on(:frame) { |bytes| socket << bytes }
|
32
|
-
interface.on(:stream) { |stream| start_stream(stream, handler) }
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
def client_loop(socket, interface)
|
37
|
-
loop do
|
38
|
-
data = socket.readpartial(8192)
|
39
|
-
break unless data
|
40
|
-
interface << data
|
41
|
-
snooze
|
42
|
-
end
|
43
|
-
rescue IOError, SystemCallError => e
|
44
|
-
# do nothing
|
45
|
-
rescue StandardError => e
|
46
|
-
puts "error in HTTP2 parse_incoming_data: #{e.inspect}"
|
47
|
-
puts e.backtrace.join("\n")
|
48
|
-
ensure
|
49
|
-
socket.close
|
50
|
-
end
|
51
|
-
|
52
|
-
# Handles HTTP 2 stream
|
53
|
-
# @param stream [HTTP2::Stream] HTTP 2 stream
|
54
|
-
# @param handler [Proc] request handler
|
55
|
-
# @return [void]
|
56
|
-
def start_stream(stream, handler)
|
57
|
-
request = Request.new(stream)
|
58
|
-
|
59
|
-
# stream.on(:active) { puts 'client opened new stream' }
|
60
|
-
# stream.on(:close) { puts 'stream closed' }
|
61
|
-
|
62
|
-
stream.on(:headers) { |h| request.set_headers(h) }
|
63
|
-
stream.on(:data) { |data| request.add_body_chunk(chunk) }
|
64
|
-
stream.on(:half_close) { handler.(request) }
|
65
|
-
end
|