polyphony 0.15 → 0.16

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.
Files changed (89) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +6 -0
  3. data/Gemfile.lock +11 -3
  4. data/TODO.md +25 -14
  5. data/docs/getting-started/getting-started.md +1 -1
  6. data/docs/getting-started/tutorial.md +2 -0
  7. data/examples/core/cancel.rb +2 -3
  8. data/examples/core/channel_echo.rb +2 -3
  9. data/examples/core/enumerator.rb +2 -3
  10. data/examples/core/fork.rb +2 -2
  11. data/examples/core/genserver.rb +2 -3
  12. data/examples/core/lock.rb +2 -3
  13. data/examples/core/move_on.rb +2 -3
  14. data/examples/core/move_on_twice.rb +2 -3
  15. data/examples/core/move_on_with_ensure.rb +2 -3
  16. data/examples/core/{multiple_async.rb → multiple_spawn.rb} +2 -3
  17. data/examples/core/nested_async.rb +2 -3
  18. data/examples/core/nested_cancel.rb +2 -3
  19. data/examples/core/{nested_multiple_async.rb → nested_multiple_spawn.rb} +2 -3
  20. data/examples/core/next_tick.rb +4 -5
  21. data/examples/core/pulse.rb +2 -3
  22. data/examples/core/resource.rb +2 -3
  23. data/examples/core/resource_cancel.rb +2 -3
  24. data/examples/core/resource_delegate.rb +2 -3
  25. data/examples/core/sleep.rb +2 -3
  26. data/examples/core/sleep_spawn.rb +19 -0
  27. data/examples/core/spawn.rb +2 -3
  28. data/examples/core/spawn_cancel.rb +2 -3
  29. data/examples/core/spawn_error.rb +2 -2
  30. data/examples/core/supervisor.rb +2 -3
  31. data/examples/core/supervisor_with_cancel_scope.rb +2 -3
  32. data/examples/core/supervisor_with_error.rb +2 -3
  33. data/examples/core/supervisor_with_manual_move_on.rb +2 -3
  34. data/examples/core/thread.rb +3 -6
  35. data/examples/core/thread_cancel.rb +2 -5
  36. data/examples/core/thread_pool.rb +3 -6
  37. data/examples/core/throttle.rb +2 -3
  38. data/examples/fs/read.rb +22 -19
  39. data/examples/http/happy_eyeballs.rb +2 -2
  40. data/examples/http/http_client.rb +5 -7
  41. data/examples/http/http_server.rb +2 -3
  42. data/examples/http/http_server_forked.rb +2 -3
  43. data/examples/http/http_server_throttled.rb +2 -3
  44. data/examples/http/http_ws_server.rb +4 -4
  45. data/examples/http/https_raw_client.rb +4 -5
  46. data/examples/http/https_server.rb +2 -3
  47. data/examples/http/https_wss_server.rb +2 -3
  48. data/examples/http/rack_server.rb +2 -4
  49. data/examples/http/rack_server_https.rb +2 -3
  50. data/examples/http/rack_server_https_forked.rb +2 -3
  51. data/examples/http/websocket_secure_server.rb +2 -3
  52. data/examples/http/websocket_server.rb +2 -3
  53. data/examples/interfaces/pg_client.rb +2 -4
  54. data/examples/interfaces/pg_pool.rb +4 -6
  55. data/examples/interfaces/{pg_query.rb → pg_transaction.rb} +2 -4
  56. data/examples/interfaces/redis_channels.rb +2 -4
  57. data/examples/interfaces/redis_client.rb +2 -4
  58. data/examples/interfaces/redis_pubsub.rb +2 -4
  59. data/examples/interfaces/redis_pubsub_perf.rb +2 -4
  60. data/examples/io/echo_client.rb +4 -5
  61. data/examples/io/echo_server.rb +2 -2
  62. data/examples/io/echo_server_with_timeout.rb +3 -5
  63. data/examples/io/echo_stdin.rb +3 -4
  64. data/examples/performance/perf_multi_snooze.rb +2 -2
  65. data/examples/performance/perf_snooze.rb +2 -2
  66. data/examples/performance/thread-vs-fiber/polyphony_server.rb +4 -5
  67. data/ext/ev/ev_module.c +3 -2
  68. data/lib/polyphony/{resource_pool.rb → core/resource_pool.rb} +0 -0
  69. data/lib/polyphony/core/supervisor.rb +8 -8
  70. data/lib/polyphony/extensions/{ssl.rb → openssl.rb} +0 -0
  71. data/lib/polyphony/http/agent.rb +1 -1
  72. data/lib/polyphony/http.rb +12 -4
  73. data/lib/polyphony/net.rb +8 -11
  74. data/lib/polyphony/{extensions/postgres.rb → postgres.rb} +1 -4
  75. data/lib/polyphony/{extensions/redis.rb → redis.rb} +3 -6
  76. data/lib/polyphony/version.rb +1 -1
  77. data/lib/polyphony/websocket.rb +1 -1
  78. data/lib/polyphony.rb +57 -21
  79. data/polyphony.gemspec +5 -4
  80. data/test/test_coprocess.rb +88 -15
  81. data/test/test_core.rb +142 -232
  82. data/test/test_ev.rb +88 -95
  83. data/test/test_io.rb +35 -41
  84. metadata +68 -16
  85. data/examples/core/sleep2.rb +0 -13
  86. data/examples/streams/lines.rb +0 -27
  87. data/examples/streams/stdio.rb +0 -18
  88. data/lib/polyphony/core.rb +0 -45
  89. data/lib/polyphony/server_task.rb +0 -18
@@ -1,8 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'modulation'
4
-
5
- Polyphony = import('../../lib/polyphony')
3
+ require 'bundler/setup'
4
+ require 'polyphony/http'
6
5
 
7
6
  $throttler = throttle(1000)
8
7
  opts = { reuse_addr: true, dont_linger: true }
@@ -1,10 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'modulation'
4
-
5
3
  STDOUT.sync = true
6
4
 
7
- Polyphony = import('../../lib/polyphony')
5
+ require 'bundler/setup'
6
+ require 'polyphony/http'
7
+ require 'polyphony/websocket'
8
8
 
9
9
  def ws_handler(conn)
10
10
  timer = spawn {
@@ -13,7 +13,7 @@ def ws_handler(conn)
13
13
  }
14
14
  }
15
15
  while msg = conn.recv
16
- # conn << "you said: #{msg}"
16
+ conn << "you said: #{msg}"
17
17
  end
18
18
  ensure
19
19
  timer.stop
@@ -1,12 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'modulation'
4
-
5
- Polyphony = import('../../lib/polyphony')
3
+ require 'bundler/setup'
4
+ require 'polyphony/http'
6
5
 
7
6
  t0 = Time.now
8
- io = Polyphony::Net.tcp_connect('realiteq.net', 443, secure: true)
9
- io.write("GET /?q=time HTTP/1.0\r\nHost: realiteq.net\r\n\r\n")
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")
10
9
  reply = io.read
11
10
  puts "time: #{Time.now - t0}"
12
11
  puts
@@ -1,10 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'modulation'
3
+ require 'bundler/setup'
4
+ require 'polyphony/http'
4
5
  require 'localhost/authority'
5
6
 
6
- Polyphony = import('../../lib/polyphony')
7
-
8
7
  authority = Localhost::Authority.fetch
9
8
  opts = {
10
9
  reuse_addr: true,
@@ -1,12 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'modulation'
3
+ require 'bundler/setup'
4
+ require 'polyphony/http'
4
5
  require 'localhost/authority'
5
6
 
6
7
  STDOUT.sync = true
7
8
 
8
- Polyphony = import('../../lib/polyphony')
9
-
10
9
  def ws_handler(conn)
11
10
  timer = spawn {
12
11
  throttled_loop(1) {
@@ -1,9 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'modulation'
4
- require 'localhost/authority'
5
-
6
- Polyphony = import('../../lib/polyphony')
3
+ require 'bundler/setup'
4
+ require 'polyphony/http'
7
5
 
8
6
  app_path = ARGV.first || File.expand_path('./config.ru', __dir__)
9
7
  app = Polyphony::HTTP::Rack.load(app_path)
@@ -1,10 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'modulation'
3
+ require 'bundler/setup'
4
+ require 'polyphony/http'
4
5
  require 'localhost/authority'
5
6
 
6
- Polyphony = import('../../lib/polyphony')
7
-
8
7
  app_path = ARGV.first || File.expand_path('./config.ru', __dir__)
9
8
  app = Polyphony::HTTP::Rack.load(app_path)
10
9
 
@@ -1,10 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'modulation'
3
+ require 'bundler/setup'
4
+ require 'polyphony/http'
4
5
  require 'localhost/authority'
5
6
 
6
- Polyphony = import('../../lib/polyphony')
7
-
8
7
  app_path = ARGV.first || File.expand_path('./config.ru', __dir__)
9
8
  app = Polyphony::HTTP::Rack.load(app_path)
10
9
 
@@ -1,12 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'modulation'
3
+ require 'bundler/setup'
4
+ require 'polyphony/http'
4
5
  require 'localhost/authority'
5
6
 
6
7
  STDOUT.sync = true
7
8
 
8
- Polyphony = import('../../lib/polyphony')
9
-
10
9
  def ws_handler(conn)
11
10
  while msg = conn.recv
12
11
  conn << "you said: #{msg}"
@@ -1,11 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'modulation'
3
+ require 'bundler/setup'
4
+ require 'polyphony/http'
4
5
 
5
6
  STDOUT.sync = true
6
7
 
7
- Polyphony = import('../../lib/polyphony')
8
-
9
8
  def ws_handler(conn)
10
9
  while msg = conn.recv
11
10
  conn << "you said: #{msg}"
@@ -1,9 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'modulation'
4
-
5
- Polyphony = import('../../lib/polyphony')
6
- Postgres = import('../../lib/polyphony/extensions/postgres')
3
+ require 'bundler/setup'
4
+ require 'polyphony/postgres'
7
5
 
8
6
  def get_records
9
7
  res = $db.query("select 1 as test")
@@ -1,9 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'modulation'
4
-
5
- Polyphony = import('../../lib/polyphony')
6
- Postgres = import('../../lib/polyphony/extensions/postgres')
3
+ require 'bundler/setup'
4
+ require 'polyphony/postgres'
7
5
 
8
6
  PGOPTS = {
9
7
  host: '/tmp',
@@ -16,7 +14,7 @@ PGOPTS = {
16
14
  DBPOOL = Polyphony::ResourcePool.new(limit: 8) { PG.connect(PGOPTS) }
17
15
 
18
16
  def get_records(db)
19
- res = db.query("select pg_sleep(0.0001) as test")
17
+ res = db.query("select pg_sleep(0.001) as test")
20
18
  # puts "got #{res.ntuples} records: #{res.to_a}"
21
19
  rescue => e
22
20
  puts "got error: #{e.inspect}"
@@ -32,6 +30,6 @@ count = 0
32
30
  coprocs = CONCURRENCY.times.map {
33
31
  spawn { loop { DBPOOL.acquire { |db| get_records(db); count += 1 } } }
34
32
  }
35
- sleep 3
33
+ sleep 5
36
34
  puts "count: #{count} query rate: #{count / (Time.now - t0)} queries/s"
37
35
  coprocs.each(&:interrupt)
@@ -1,9 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'modulation'
4
-
5
- Polyphony = import('../../lib/polyphony')
6
- Postgres = import('../../lib/polyphony/extensions/postgres')
3
+ require 'bundler/setup'
4
+ require 'polyphony/postgres'
7
5
 
8
6
  DB = PG.connect(
9
7
  host: '/tmp',
@@ -1,9 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'modulation'
4
-
5
- Polyphony = import('../../lib/polyphony')
6
- import('../../lib/polyphony/extensions/redis')
3
+ require 'bundler/setup'
4
+ require 'polyphony/redis'
7
5
 
8
6
  class RedisChannel < Polyphony::Channel
9
7
  def self.publish_connection
@@ -1,9 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'modulation'
4
-
5
- Polyphony = import('../../lib/polyphony')
6
- import('../../lib/polyphony/extensions/redis')
3
+ require 'bundler/setup'
4
+ require 'polyphony/redis'
7
5
 
8
6
  redis = Redis.new
9
7
 
@@ -1,9 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'modulation'
4
-
5
- Polyphony = import('../../lib/polyphony')
6
- import('../../lib/polyphony/extensions/redis')
3
+ require 'bundler/setup'
4
+ require 'polyphony/redis'
7
5
 
8
6
  spawn do
9
7
  redis = Redis.new
@@ -1,11 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'modulation'
3
+ require 'bundler/setup'
4
+ require 'polyphony/redis'
4
5
  require 'json'
5
6
 
6
- Polyphony = import('../../lib/polyphony')
7
- import('../../lib/polyphony/extensions/redis')
8
-
9
7
  X_SESSIONS = 1000
10
8
  X_NODES = 10000
11
9
  X_SUBSCRIPTIONS_PER_SESSION = 100
@@ -1,18 +1,17 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'modulation'
4
-
5
- Polyphony = import('../../lib/polyphony')
3
+ require 'bundler/setup'
4
+ require 'polyphony'
6
5
 
7
6
  socket = Polyphony::Net.tcp_connect('127.0.0.1', 1234)
8
7
 
9
8
  writer = spawn do
10
- throttled_loop(1) { socket << "#{Time.now}\n" }
9
+ throttled_loop(1) { socket << "#{Time.now}\n" rescue nil }
11
10
  end
12
11
 
13
12
  reader = spawn do
14
13
  puts "received from echo server:"
15
- while data = socket.read
14
+ while data = socket.readpartial(8192)
16
15
  STDOUT << data
17
16
  end
18
17
  end
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'modulation'
4
- Polyphony = import('../../lib/polyphony')
3
+ require 'bundler/setup'
4
+ require 'polyphony'
5
5
 
6
6
  server = TCPServer.open(1234)
7
7
  puts "Echoing on port 1234..."
@@ -1,8 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'modulation'
4
-
5
- Polyphony = import('../../lib/polyphony')
3
+ require 'bundler/setup'
4
+ require 'polyphony'
6
5
 
7
6
  begin
8
7
  server = Polyphony::Net.tcp_listen(nil, 1234, reuse_addr: true, dont_linger: true)
@@ -14,8 +13,7 @@ begin
14
13
  cancel_scope = nil
15
14
  move_on_after(5) do |s|
16
15
  cancel_scope = s
17
- loop do
18
- data = client.read
16
+ while (data = client.readpartial(8192))
19
17
  s.reset_timeout
20
18
  client.write(data)
21
19
  end
@@ -1,13 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'modulation'
4
-
5
- Polyphony = import('../../lib/polyphony')
3
+ require 'bundler/setup'
4
+ require 'polyphony'
6
5
 
7
6
  puts "Write something..."
8
7
  move_on_after(5) do |scope|
9
8
  loop do
10
- data = STDIN.read
9
+ data = STDIN.readpartial(8192)
11
10
  scope.reset_timeout
12
11
  puts "you wrote: #{data}"
13
12
  end
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'modulation'
4
- Polyphony = import('../../lib/polyphony')
3
+ require 'bundler/setup'
4
+ require 'polyphony'
5
5
 
6
6
  ITERATIONS = 1_000
7
7
  FIBERS = 1_000
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'modulation'
4
- Polyphony = import('../../lib/polyphony')
3
+ require 'bundler/setup'
4
+ require 'polyphony'
5
5
 
6
6
  X = 1_000_000
7
7
 
@@ -1,10 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'modulation'
3
+ require 'bundler/setup'
4
+ require 'polyphony'
4
5
  require 'http/parser'
5
6
 
6
- Polyphony = import('../../../lib/polyphony')
7
-
8
7
  class Http::Parser
9
8
  def setup_async
10
9
  self.on_message_complete = proc { @request_complete = true }
@@ -25,8 +24,8 @@ async def handle_client(socket)
25
24
  parser.on_message_complete = proc do |env|
26
25
  req = parser
27
26
  end
28
- loop do
29
- parser << socket.read
27
+ while (data = socket.readpartial(8192)) do
28
+ parser << data
30
29
  if req
31
30
  handle_request(socket, req)
32
31
  req = nil
data/ext/ev/ev_module.c CHANGED
@@ -54,8 +54,9 @@ void Init_EV() {
54
54
  rb_define_singleton_method(mEV, "post_fork", EV_post_fork, 0);
55
55
  rb_define_singleton_method(mEV, "schedule_fiber", EV_schedule_fiber, 2);
56
56
 
57
- rb_define_method(rb_mKernel, "suspend", EV_suspend, 0);
58
- rb_define_method(rb_mKernel, "snooze", EV_snooze, 0);
57
+ rb_define_global_function("suspend", EV_suspend, 0);
58
+ rb_define_global_function("snooze", EV_snooze, 0);
59
+ rb_define_global_function("next_tick", EV_next_tick, 0);
59
60
 
60
61
  ID_call = rb_intern("call");
61
62
  ID_caller = rb_intern("caller");
@@ -7,7 +7,7 @@ Exceptions = import('./exceptions')
7
7
 
8
8
  class Supervisor
9
9
  def initialize
10
- @coprocesss = []
10
+ @coprocesses = []
11
11
  end
12
12
 
13
13
  def await(&block)
@@ -34,14 +34,14 @@ class Supervisor
34
34
  end
35
35
 
36
36
  def spawn_coprocess(proc)
37
- @coprocesss << proc
37
+ @coprocesses << proc
38
38
  proc.when_done { task_completed(proc) }
39
39
  proc.run unless proc.running?
40
40
  proc
41
41
  end
42
42
 
43
43
  def spawn_proc(proc)
44
- @coprocesss << Object.spawn do |coprocess|
44
+ @coprocesses << Object.spawn do |coprocess|
45
45
  proc.call(coprocess)
46
46
  task_completed(coprocess)
47
47
  rescue Exception => e
@@ -50,7 +50,7 @@ class Supervisor
50
50
  end
51
51
 
52
52
  def still_running?
53
- !@coprocesss.empty?
53
+ !@coprocesses.empty?
54
54
  end
55
55
 
56
56
  def stop!(result = nil)
@@ -62,15 +62,15 @@ class Supervisor
62
62
 
63
63
  def stop_all_tasks
64
64
  exception = Exceptions::Stop.new
65
- @coprocesss.each do |c|
65
+ @coprocesses.each do |c|
66
66
  EV.next_tick { c.interrupt(exception) }
67
67
  end
68
68
  end
69
69
 
70
70
  def task_completed(coprocess)
71
- return unless @coprocesss.include?(coprocess)
71
+ return unless @coprocesses.include?(coprocess)
72
72
 
73
- @coprocesss.delete(coprocess)
74
- @supervisor_fiber&.transfer if @coprocesss.empty?
73
+ @coprocesses.delete(coprocess)
74
+ @supervisor_fiber&.transfer if @coprocesses.empty?
75
75
  end
76
76
  end
File without changes
@@ -7,7 +7,7 @@ require 'http/parser'
7
7
  require 'http/2'
8
8
  require 'json'
9
9
 
10
- ResourcePool = import('../resource_pool')
10
+ ResourcePool = import('../core/resource_pool')
11
11
 
12
12
  module ResponseMixin
13
13
  def body
@@ -1,7 +1,15 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- export :Server
3
+ require_relative '../polyphony'
4
4
 
5
- auto_import(
6
- Server: './http/server'
7
- )
5
+ module Polyphony
6
+ module HTTP
7
+ auto_import(
8
+ Agent: './http/agent',
9
+ Rack: './http/rack',
10
+ Server: './http/server',
11
+ )
12
+ end
13
+ end
14
+
15
+ export_default Polyphony::HTTP
data/lib/polyphony/net.rb CHANGED
@@ -1,14 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  export :tcp_connect,
4
- :tcp_listen#,
5
- # :getaddrinfo
4
+ :tcp_listen
6
5
 
7
6
  import('./extensions/socket')
8
- import('./extensions/ssl')
7
+ import('./extensions/openssl')
9
8
 
10
9
  def tcp_connect(host, port, opts = {})
11
- puts "tcp_connect(#{host.inspect}, #{port.inspect}, #{opts.inspect})"
12
10
  socket = ::Socket.new(:INET, :STREAM).tap { |s|
13
11
  addr = ::Socket.sockaddr_in(port, host)
14
12
  s.connect(addr)
@@ -37,17 +35,16 @@ def tcp_listen(host = nil, port = nil, opts = {})
37
35
  end
38
36
  end
39
37
 
40
- DEFAULT_SSL_CONTEXT = OpenSSL::SSL::SSLContext.new
41
- DEFAULT_SSL_CONTEXT.set_params(verify_mode: OpenSSL::SSL::VERIFY_PEER)
42
-
43
38
  def secure_socket(socket, context, opts)
44
- context ||= DEFAULT_SSL_CONTEXT
45
- setup_alpn(context, opts[:alpn_protocols]) if opts[:alpn_protocols]
46
- OpenSSL::SSL::SSLSocket.new(socket, context).tap { |s| s.connect }
39
+ if context
40
+ setup_alpn(context, opts[:alpn_protocols]) if opts[:alpn_protocols]
41
+ OpenSSL::SSL::SSLSocket.new(socket, context).tap { |s| s.connect }
42
+ else
43
+ OpenSSL::SSL::SSLSocket.new(socket).tap { |s| s.connect }
44
+ end
47
45
  end
48
46
 
49
47
  def secure_server(socket, context, opts)
50
- context ||= DEFAULT_SSL_CONTEXT
51
48
  setup_alpn(context, opts[:alpn_protocols]) if opts[:alpn_protocols]
52
49
  OpenSSL::SSL::SSLServer.new(socket, context)
53
50
  end
@@ -1,11 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- export :Client
4
-
3
+ require_relative '../polyphony'
5
4
  require 'pg'
6
5
 
7
- Core = import('../core')
8
-
9
6
  module ::PG
10
7
  def self.connect(*args)
11
8
  Connection.connect_start(*args).tap(&method(:connect_async))
@@ -1,12 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- export :Driver
3
+ require_relative '../polyphony'
4
4
 
5
5
  require "redis"
6
6
  require "hiredis/reader"
7
7
 
8
- Net = import('../net')
9
-
10
8
  class Driver
11
9
  def self.connect(config)
12
10
  if config[:scheme] == "unix"
@@ -22,7 +20,7 @@ class Driver
22
20
  end
23
21
 
24
22
  def initialize(host, port)
25
- @connection = Net.tcp_connect(host, port)
23
+ @connection = Polyphony::Net.tcp_connect(host, port)
26
24
  @reader = ::Hiredis::Reader.new
27
25
  end
28
26
 
@@ -56,8 +54,7 @@ class Driver
56
54
  reply = @reader.gets
57
55
  return reply if reply
58
56
 
59
- loop do
60
- data = @connection.read
57
+ while (data = @connection.readpartial(8192))
61
58
  @reader.feed(data)
62
59
  reply = @reader.gets
63
60
  return reply if reply
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Polyphony
4
- VERSION = '0.15'
4
+ VERSION = '0.16'
5
5
  end
@@ -8,7 +8,7 @@ require 'websocket'
8
8
  class WebsocketConnection
9
9
  def initialize(client, headers)
10
10
  @client = client
11
- @headers = headers
11
+ @headers = headers
12
12
  setup(headers)
13
13
  end
14
14