polyphony 0.23 → 0.24
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +7 -0
- data/Gemfile.lock +4 -10
- data/README.md +0 -4
- data/TODO.md +5 -56
- data/docs/README.md +4 -7
- data/examples/core/{channel_echo.rb → xx-channels.rb} +0 -0
- data/examples/core/{defer.rb → xx-deferring-an-operation.rb} +0 -0
- data/examples/core/{genserver.rb → xx-erlang-style-genserver.rb} +2 -2
- data/examples/core/{fork.rb → xx-forking.rb} +2 -0
- data/examples/core/xx-move_on.rb +23 -0
- data/examples/core/{pulse.rb → xx-recurrent-timer.rb} +3 -2
- data/examples/core/{resource_cancel.rb → xx-resource_cancel.rb} +1 -2
- data/examples/core/{resource_delegate.rb → xx-resource_delegate.rb} +0 -0
- data/examples/core/{wait_for_signal.rb → xx-signals.rb} +0 -0
- data/examples/core/{sleep.rb → xx-sleeping.rb} +0 -0
- data/examples/core/{spin_error_backtrace.rb → xx-spin_error_backtrace.rb} +5 -2
- data/examples/core/{supervisor.rb → xx-supervisors.rb} +0 -0
- data/examples/core/{thread_cancel.rb → xx-thread_cancel.rb} +0 -0
- data/examples/core/{thread_pool.rb → xx-thread_pool.rb} +0 -0
- data/examples/core/{throttle.rb → xx-throttling.rb} +0 -0
- data/examples/core/{timeout.rb → xx-timeout.rb} +0 -0
- data/examples/core/{lock.rb → xx-using-a-mutex.rb} +0 -0
- data/examples/io/{backticks.rb → xx-backticks.rb} +0 -0
- data/examples/io/{echo_client.rb → xx-echo_client.rb} +0 -1
- data/examples/io/{echo_client_from_stdin.rb → xx-echo_client_from_stdin.rb} +0 -1
- data/examples/io/{echo_pipe.rb → xx-echo_pipe.rb} +0 -0
- data/examples/io/{echo_server.rb → xx-echo_server.rb} +0 -0
- data/examples/io/{echo_server_with_timeout.rb → xx-echo_server_with_timeout.rb} +0 -0
- data/examples/io/{echo_stdin.rb → xx-echo_stdin.rb} +0 -0
- data/examples/io/xx-httparty.rb +13 -0
- data/examples/io/{irb.rb → xx-irb.rb} +0 -0
- data/examples/io/{net-http.rb → xx-net-http.rb} +0 -0
- data/examples/io/{open.rb → xx-open.rb} +0 -1
- data/examples/io/{system.rb → xx-system.rb} +0 -0
- data/examples/io/{tcpserver.rb → xx-tcpserver.rb} +0 -0
- data/examples/io/{tcpsocket.rb → xx-tcpsocket.rb} +0 -1
- data/examples/{fs/read.rb → performance/fs_read.rb} +0 -0
- data/examples/{core → performance}/mem-usage.rb +1 -0
- data/examples/performance/multi_snooze.rb +2 -0
- data/examples/performance/snooze.rb +2 -0
- data/examples/performance/thread-vs-fiber/polyphony_server.rb +5 -3
- data/examples/performance/thread-vs-fiber/threaded_server.rb +1 -1
- data/examples/{io/httparty_multi.rb → performance/thread-vs-fiber/xx-httparty_multi.rb} +16 -13
- data/examples/{io/httparty_threaded.rb → performance/thread-vs-fiber/xx-httparty_threaded.rb} +2 -2
- data/examples/performance/thread.rb +27 -0
- data/examples/{core → performance}/thread_pool_perf.rb +0 -0
- data/ext/gyro/extconf.rb +1 -0
- data/lib/polyphony/extensions/core.rb +0 -5
- data/lib/polyphony/version.rb +1 -1
- data/polyphony.gemspec +3 -9
- metadata +59 -167
- data/bin/poly +0 -11
- data/examples/core/cancel.rb +0 -13
- data/examples/core/enumerator.rb +0 -15
- data/examples/core/error_bubbling.rb +0 -35
- data/examples/core/fiber_error.rb +0 -9
- data/examples/core/fiber_error_with_backtrace.rb +0 -73
- data/examples/core/move_on.rb +0 -11
- data/examples/core/move_on_twice.rb +0 -16
- data/examples/core/move_on_with_ensure.rb +0 -13
- data/examples/core/move_on_with_value.rb +0 -14
- data/examples/core/multiple_spin.rb +0 -18
- data/examples/core/nested_cancel.rb +0 -40
- data/examples/core/nested_multiple_spin.rb +0 -20
- data/examples/core/nested_spin.rb +0 -19
- data/examples/core/pingpong.rb +0 -21
- data/examples/core/resource.rb +0 -30
- data/examples/core/sleep_spin.rb +0 -21
- data/examples/core/snooze.rb +0 -32
- data/examples/core/spin_error.rb +0 -17
- data/examples/core/spin_uncaught_error.rb +0 -16
- data/examples/core/supervisor_with_cancel_scope.rb +0 -23
- data/examples/core/supervisor_with_error.rb +0 -24
- data/examples/core/supervisor_with_manual_move_on.rb +0 -23
- data/examples/core/suspend.rb +0 -13
- data/examples/core/thread.rb +0 -27
- data/examples/http/config.ru +0 -7
- data/examples/http/cuba.ru +0 -22
- data/examples/http/happy_eyeballs.rb +0 -37
- data/examples/http/http2_raw.rb +0 -135
- data/examples/http/http_client.rb +0 -28
- data/examples/http/http_get.rb +0 -33
- data/examples/http/http_parse_experiment.rb +0 -123
- data/examples/http/http_proxy.rb +0 -83
- data/examples/http/http_server.js +0 -24
- data/examples/http/http_server.rb +0 -28
- data/examples/http/http_server_forked.rb +0 -29
- data/examples/http/http_server_graceful.rb +0 -27
- data/examples/http/http_server_simple.rb +0 -11
- data/examples/http/http_server_throttled.rb +0 -15
- data/examples/http/http_ws_server.rb +0 -37
- data/examples/http/https_raw_client.rb +0 -12
- data/examples/http/https_server.rb +0 -22
- data/examples/http/https_wss_server.rb +0 -39
- data/examples/http/rack_server.rb +0 -12
- data/examples/http/rack_server_https.rb +0 -19
- data/examples/http/rack_server_https_forked.rb +0 -27
- data/examples/http/websocket_secure_server.rb +0 -27
- data/examples/http/websocket_server.rb +0 -24
- data/examples/http/ws_page.html +0 -34
- data/examples/http/wss_page.html +0 -34
- data/examples/io/cat.rb +0 -12
- data/examples/io/httparty.rb +0 -10
- data/examples/io/io_read.rb +0 -9
- data/lib/ev_ext.bundle +0 -0
- data/lib/polyphony/http.rb +0 -16
- data/lib/polyphony/http/client/agent.rb +0 -131
- data/lib/polyphony/http/client/http1.rb +0 -129
- data/lib/polyphony/http/client/http2.rb +0 -180
- data/lib/polyphony/http/client/response.rb +0 -32
- data/lib/polyphony/http/client/site_connection_manager.rb +0 -109
- data/lib/polyphony/http/server.rb +0 -49
- data/lib/polyphony/http/server/http1.rb +0 -268
- data/lib/polyphony/http/server/http2.rb +0 -78
- data/lib/polyphony/http/server/http2_stream.rb +0 -136
- data/lib/polyphony/http/server/rack.rb +0 -64
- data/lib/polyphony/http/server/request.rb +0 -118
- data/lib/polyphony/websocket.rb +0 -59
- data/test/test_http_server.rb +0 -313
data/examples/http/http_proxy.rb
DELETED
@@ -1,83 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'bundler/setup'
|
4
|
-
require 'polyphony/http'
|
5
|
-
require 'localhost/authority'
|
6
|
-
|
7
|
-
# p Polyphony::HTTP::Agent.get('https://ui.realiteq.net/', q: :time)
|
8
|
-
|
9
|
-
BASE_URL = 'http://realiteq.net'
|
10
|
-
|
11
|
-
CACHE = {}.freeze
|
12
|
-
|
13
|
-
def proxy(uri, opts)
|
14
|
-
now = Time.now
|
15
|
-
uri = BASE_URL + uri
|
16
|
-
entry = CACHE[uri]
|
17
|
-
return entry[:response] if entry && entry[:expires] >= now
|
18
|
-
|
19
|
-
puts "proxy => #{uri} (#{opts.inspect})"
|
20
|
-
response = Polyphony::HTTP::Agent.get(uri, opts)
|
21
|
-
# CACHE[uri] = {
|
22
|
-
# expires: now + 60,
|
23
|
-
# response: response
|
24
|
-
# }
|
25
|
-
response
|
26
|
-
end
|
27
|
-
|
28
|
-
HEADERS_BLACK_LIST = %w[
|
29
|
-
Transfer-Encoding Date Server Connection Content-Length Cache-Control
|
30
|
-
:method :authority :scheme :path
|
31
|
-
].freeze
|
32
|
-
|
33
|
-
def sanitize_headers(headers)
|
34
|
-
headers.reject { |k, _v| HEADERS_BLACK_LIST.include?(k) }
|
35
|
-
end
|
36
|
-
|
37
|
-
def sanitize_html(html)
|
38
|
-
# html.gsub('http://martigny-le-comte.fr/', '/')
|
39
|
-
end
|
40
|
-
|
41
|
-
# authority = Localhost::Authority.fetch
|
42
|
-
|
43
|
-
rsa_cert = OpenSSL::X509::Certificate.new(
|
44
|
-
IO.read('../reality/aws/config/ssl/full_chain.pem')
|
45
|
-
)
|
46
|
-
rsa_pkey = OpenSSL::PKey.read(
|
47
|
-
IO.read('../reality/aws/config/ssl/private_key.pem')
|
48
|
-
)
|
49
|
-
ctx = OpenSSL::SSL::SSLContext.new
|
50
|
-
ctx.add_certificate(rsa_cert, rsa_pkey)
|
51
|
-
|
52
|
-
opts = {
|
53
|
-
reuse_addr: true,
|
54
|
-
dont_linger: true,
|
55
|
-
secure_context: ctx # authority.server_context
|
56
|
-
}
|
57
|
-
|
58
|
-
spin do
|
59
|
-
Polyphony::HTTP::Server.serve('0.0.0.0', 1234, opts) do |req|
|
60
|
-
puts "#{req.method} #{req.uri}"
|
61
|
-
puts "headers <: #{req.headers.inspect}"
|
62
|
-
# h = {
|
63
|
-
# uri: req.uri.to_s,
|
64
|
-
# protocol: req.protocol,
|
65
|
-
# headers: req.headers,
|
66
|
-
# body: req.body,
|
67
|
-
# }
|
68
|
-
response = proxy(req.uri.to_s, headers: sanitize_headers(req.headers))
|
69
|
-
headers = sanitize_headers(response[:headers])
|
70
|
-
body = response[:body]
|
71
|
-
# puts "body class: #{body.class}"
|
72
|
-
puts "headers >: #{response[:headers].inspect}"
|
73
|
-
# body = sanitize_html(body) if headers['Content-Type'] =~ /text\/html/
|
74
|
-
req.respond(body, headers)
|
75
|
-
rescue StandardError => e
|
76
|
-
puts 'error'
|
77
|
-
p e
|
78
|
-
puts e.backtrace.join("\n")
|
79
|
-
end
|
80
|
-
end
|
81
|
-
|
82
|
-
puts "pid: #{Process.pid}"
|
83
|
-
puts 'Listening on port 1234...'
|
@@ -1,24 +0,0 @@
|
|
1
|
-
// For the sake of comparing performance, here's a node.js-based HTTP server
|
2
|
-
// doing roughly the same thing as http_server. Preliminary benchmarking shows
|
3
|
-
// the ruby version has a throughput (req/s) of about 2/3 of the JS version.
|
4
|
-
|
5
|
-
const http = require('http');
|
6
|
-
|
7
|
-
const MSG = 'Hello World';
|
8
|
-
|
9
|
-
const server = http.createServer((req, res) => {
|
10
|
-
// let requestCopy = {
|
11
|
-
// method: req.method,
|
12
|
-
// request_url: req.url,
|
13
|
-
// headers: req.headers
|
14
|
-
// };
|
15
|
-
|
16
|
-
// res.writeHead(200, { 'Content-Type': 'application/json' });
|
17
|
-
// res.end(JSON.stringify(requestCopy));
|
18
|
-
|
19
|
-
res.writeHead(200);
|
20
|
-
res.end(MSG)
|
21
|
-
});
|
22
|
-
|
23
|
-
server.listen(1235);
|
24
|
-
console.log('Listening on port 1235');
|
@@ -1,28 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'bundler/setup'
|
4
|
-
require 'polyphony'
|
5
|
-
require 'polyphony/http'
|
6
|
-
|
7
|
-
opts = {
|
8
|
-
reuse_addr: true,
|
9
|
-
dont_linger: true
|
10
|
-
}
|
11
|
-
|
12
|
-
spin do
|
13
|
-
Polyphony::HTTP::Server.serve('0.0.0.0', 1234, opts) do |req|
|
14
|
-
req.respond("Hello world!\n")
|
15
|
-
rescue Exception => e
|
16
|
-
p e
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
spin do
|
21
|
-
throttled_loop(1) do
|
22
|
-
puts "#{Time.now} coprocess count: #{Polyphony::Coprocess.list.size}"
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
puts "pid: #{Process.pid}"
|
27
|
-
puts 'Listening on port 1234...'
|
28
|
-
suspend
|
@@ -1,29 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'bundler/setup'
|
4
|
-
require 'polyphony/http'
|
5
|
-
|
6
|
-
::Exception.__disable_sanitized_backtrace__ = true
|
7
|
-
|
8
|
-
opts = {
|
9
|
-
reuse_addr: true,
|
10
|
-
dont_linger: true
|
11
|
-
}
|
12
|
-
|
13
|
-
server = Polyphony::HTTP::Server.listen('0.0.0.0', 1234, opts)
|
14
|
-
|
15
|
-
puts 'Listening on port 1234'
|
16
|
-
|
17
|
-
child_pids = []
|
18
|
-
4.times do
|
19
|
-
pid = Polyphony.fork do
|
20
|
-
puts "forked pid: #{Process.pid}"
|
21
|
-
server.each do |req|
|
22
|
-
req.respond("Hello world! from pid: #{Process.pid}\n")
|
23
|
-
end
|
24
|
-
rescue Interrupt
|
25
|
-
end
|
26
|
-
child_pids << pid
|
27
|
-
end
|
28
|
-
|
29
|
-
child_pids.each { |pid| Gyro::Child.new(pid).await }
|
@@ -1,27 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'bundler/setup'
|
4
|
-
require 'polyphony'
|
5
|
-
require 'polyphony/http'
|
6
|
-
|
7
|
-
opts = {
|
8
|
-
reuse_addr: true,
|
9
|
-
dont_linger: true
|
10
|
-
}
|
11
|
-
|
12
|
-
server = spin do
|
13
|
-
Polyphony::HTTP::Server.serve('0.0.0.0', 1234, opts) do |req|
|
14
|
-
req.respond("Hello world!\n")
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
trap('SIGHUP') do
|
19
|
-
puts 'got hup'
|
20
|
-
server.interrupt
|
21
|
-
end
|
22
|
-
|
23
|
-
puts "pid: #{Process.pid}"
|
24
|
-
puts 'Send HUP to stop gracefully'
|
25
|
-
puts 'Listening on port 1234...'
|
26
|
-
|
27
|
-
suspend
|
@@ -1,15 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'bundler/setup'
|
4
|
-
require 'polyphony/http'
|
5
|
-
|
6
|
-
$throttler = throttle(1000)
|
7
|
-
opts = { reuse_addr: true, dont_linger: true }
|
8
|
-
spin do
|
9
|
-
Polyphony::HTTP::Server.serve('0.0.0.0', 1234, opts) do |req|
|
10
|
-
$throttler.call { req.respond("Hello world!\n") }
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
puts "pid: #{Process.pid}"
|
15
|
-
puts 'Listening on port 1234...'
|
@@ -1,37 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'bundler/setup'
|
4
|
-
require 'polyphony/http'
|
5
|
-
require 'polyphony/websocket'
|
6
|
-
|
7
|
-
def ws_handler(conn)
|
8
|
-
timer = spin do
|
9
|
-
throttled_loop(1) do
|
10
|
-
conn << Time.now.to_s
|
11
|
-
end
|
12
|
-
end
|
13
|
-
while (msg = conn.recv)
|
14
|
-
conn << "you said: #{msg}"
|
15
|
-
end
|
16
|
-
ensure
|
17
|
-
timer.stop
|
18
|
-
end
|
19
|
-
|
20
|
-
opts = {
|
21
|
-
reuse_addr: true,
|
22
|
-
dont_linger: true,
|
23
|
-
upgrade: {
|
24
|
-
websocket: Polyphony::Websocket.handler(&method(:ws_handler))
|
25
|
-
}
|
26
|
-
}
|
27
|
-
|
28
|
-
HTML = IO.read(File.join(__dir__, 'ws_page.html'))
|
29
|
-
|
30
|
-
spin do
|
31
|
-
Polyphony::HTTP::Server.serve('0.0.0.0', 1234, opts) do |req|
|
32
|
-
req.respond(HTML, 'Content-Type' => 'text/html')
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
puts "pid: #{Process.pid}"
|
37
|
-
puts 'Listening on port 1234...'
|
@@ -1,12 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'bundler/setup'
|
4
|
-
require 'polyphony/http'
|
5
|
-
|
6
|
-
t0 = Time.now
|
7
|
-
io = Polyphony::Net.tcp_connect('google.com', 443, secure: true)
|
8
|
-
io.write("GET / HTTP/1.0\r\nHost: realiteq.net\r\n\r\n")
|
9
|
-
reply = io.read
|
10
|
-
puts "time: #{Time.now - t0}"
|
11
|
-
puts
|
12
|
-
puts reply
|
@@ -1,22 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'bundler/setup'
|
4
|
-
require 'polyphony/http'
|
5
|
-
require 'localhost/authority'
|
6
|
-
|
7
|
-
authority = Localhost::Authority.fetch
|
8
|
-
opts = {
|
9
|
-
reuse_addr: true,
|
10
|
-
dont_linger: true,
|
11
|
-
secure_context: authority.server_context
|
12
|
-
}
|
13
|
-
|
14
|
-
puts "pid: #{Process.pid}"
|
15
|
-
puts 'Listening on port 1234...'
|
16
|
-
Polyphony::HTTP::Server.serve('0.0.0.0', 1234, opts) do |req|
|
17
|
-
req.respond("Hello world!\n")
|
18
|
-
# req.send_headers
|
19
|
-
# req.send_chunk("Method: #{req.method}\n")
|
20
|
-
# req.send_chunk("Path: #{req.path}\n")
|
21
|
-
# req.send_chunk("Query: #{req.query.inspect}\n", done: true)
|
22
|
-
end
|
@@ -1,39 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'bundler/setup'
|
4
|
-
require 'polyphony/http'
|
5
|
-
require 'localhost/authority'
|
6
|
-
|
7
|
-
def ws_handler(conn)
|
8
|
-
timer = spin do
|
9
|
-
throttled_loop(1) do
|
10
|
-
conn << Time.now.to_s
|
11
|
-
rescue StandardError
|
12
|
-
nil
|
13
|
-
end
|
14
|
-
end
|
15
|
-
while (msg = conn.recv)
|
16
|
-
puts "msg: #{msg}"
|
17
|
-
# conn << "you said: #{msg}"
|
18
|
-
end
|
19
|
-
ensure
|
20
|
-
timer.stop
|
21
|
-
end
|
22
|
-
|
23
|
-
authority = Localhost::Authority.fetch
|
24
|
-
opts = {
|
25
|
-
reuse_addr: true,
|
26
|
-
dont_linger: true,
|
27
|
-
secure_context: authority.server_context,
|
28
|
-
upgrade: {
|
29
|
-
websocket: Polyphony::Websocket.handler(&method(:ws_handler))
|
30
|
-
}
|
31
|
-
}
|
32
|
-
|
33
|
-
HTML = IO.read(File.join(__dir__, 'wss_page.html'))
|
34
|
-
|
35
|
-
puts "pid: #{Process.pid}"
|
36
|
-
puts 'Listening on port 1234...'
|
37
|
-
Polyphony::HTTP::Server.serve('0.0.0.0', 1234, opts) do |req|
|
38
|
-
req.respond(HTML, 'Content-Type' => 'text/html')
|
39
|
-
end
|
@@ -1,12 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'bundler/setup'
|
4
|
-
require 'polyphony/http'
|
5
|
-
|
6
|
-
app_path = ARGV.first || File.expand_path('./config.ru', __dir__)
|
7
|
-
app = Polyphony::HTTP::Rack.load(app_path)
|
8
|
-
opts = { reuse_addr: true, dont_linger: true }
|
9
|
-
|
10
|
-
puts 'listening on port 1234'
|
11
|
-
puts "pid: #{Process.pid}"
|
12
|
-
Polyphony::HTTP::Server.serve('0.0.0.0', 1234, opts, &app)
|
@@ -1,19 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'bundler/setup'
|
4
|
-
require 'polyphony/http'
|
5
|
-
require 'localhost/authority'
|
6
|
-
|
7
|
-
app_path = ARGV.first || File.expand_path('./config.ru', __dir__)
|
8
|
-
app = Polyphony::HTTP::Rack.load(app_path)
|
9
|
-
|
10
|
-
authority = Localhost::Authority.fetch
|
11
|
-
opts = {
|
12
|
-
reuse_addr: true,
|
13
|
-
dont_linger: true,
|
14
|
-
secure_context: authority.server_context
|
15
|
-
}
|
16
|
-
|
17
|
-
puts 'listening on port 1234'
|
18
|
-
puts "pid: #{Process.pid}"
|
19
|
-
Polyphony::HTTP::Server.serve('0.0.0.0', 1234, opts, &app)
|
@@ -1,27 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'bundler/setup'
|
4
|
-
require 'polyphony/http'
|
5
|
-
require 'localhost/authority'
|
6
|
-
|
7
|
-
app_path = ARGV.first || File.expand_path('./config.ru', __dir__)
|
8
|
-
app = Polyphony::HTTP::Rack.load(app_path)
|
9
|
-
|
10
|
-
authority = Localhost::Authority.fetch
|
11
|
-
opts = {
|
12
|
-
reuse_addr: true,
|
13
|
-
dont_linger: true,
|
14
|
-
secure_context: authority.server_context
|
15
|
-
}
|
16
|
-
server = Polyphony::HTTP::Server.listen('0.0.0.0', 1234, opts)
|
17
|
-
puts 'Listening on port 1234'
|
18
|
-
|
19
|
-
child_pids = []
|
20
|
-
4.times do
|
21
|
-
child_pids << Polyphony.fork do
|
22
|
-
puts "forked pid: #{Process.pid}"
|
23
|
-
server.each(&app)
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
child_pids.each { |pid| EV::Child.new(pid).await }
|
@@ -1,27 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'bundler/setup'
|
4
|
-
require 'polyphony/http'
|
5
|
-
require 'localhost/authority'
|
6
|
-
|
7
|
-
def ws_handler(conn)
|
8
|
-
while (msg = conn.recv)
|
9
|
-
conn << "you said: #{msg}"
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
authority = Localhost::Authority.fetch
|
14
|
-
opts = {
|
15
|
-
reuse_addr: true,
|
16
|
-
dont_linger: true,
|
17
|
-
upgrade: {
|
18
|
-
websocket: Polyphony::Websocket.handler(&method(:ws_handler))
|
19
|
-
},
|
20
|
-
secure_context: authority.server_context
|
21
|
-
}
|
22
|
-
|
23
|
-
puts "pid: #{Process.pid}"
|
24
|
-
puts 'Listening on port 1234...'
|
25
|
-
Polyphony::HTTP::Server.serve('0.0.0.0', 1234, opts) do |req|
|
26
|
-
req.respond("Hello world!\n")
|
27
|
-
end
|
@@ -1,24 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'bundler/setup'
|
4
|
-
require 'polyphony/http'
|
5
|
-
|
6
|
-
def ws_handler(conn)
|
7
|
-
while (msg = conn.recv)
|
8
|
-
conn << "you said: #{msg}"
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
opts = {
|
13
|
-
reuse_addr: true,
|
14
|
-
dont_linger: true,
|
15
|
-
upgrade: {
|
16
|
-
websocket: Polyphony::Websocket.handler(&method(:ws_handler))
|
17
|
-
}
|
18
|
-
}
|
19
|
-
|
20
|
-
puts "pid: #{Process.pid}"
|
21
|
-
puts 'Listening on port 1234...'
|
22
|
-
Polyphony::HTTP::Server.serve('0.0.0.0', 1234, opts) do |req|
|
23
|
-
req.respond("Hello world!\n")
|
24
|
-
end
|