plum 0.2.9 → 0.2.10

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8e0e1f798c885a09557e220ac446f6c0aa048efe
4
- data.tar.gz: dd31a046c57dd142b85940f4b970e90441d2f490
3
+ metadata.gz: ef27822edb349c4af6092ad5e6fcfa7a197c4300
4
+ data.tar.gz: a958711115e3c29dbe9f084a831d8167005c873e
5
5
  SHA512:
6
- metadata.gz: 7d19e7d4c6f8b868d6c12824d62848f1532fe34af9dd04bc7128396a51533bbfe6c9c68bb36456c63a90e5fc2a337994d76b89ce0aa32bccb03616edf878a91e
7
- data.tar.gz: aae1851fa3169ffb041a7efd3563dceee256e7e2aed653e6a8ffe1d8b3163bb7a32977abe02bee7ef86a5d91e792d555d1dd19bac40b72820549fa11c07d154e
6
+ metadata.gz: 58378f43aee9a6c53e4b87d1e8f4b3a0969f79e10981eaf51af23327108d037e3d5dde0e56a090f04d749fae687262cdd45bb50f59e5201f90844568addc55c8
7
+ data.tar.gz: 1450a4e93f8a8929740c3cbd9edd5018294312cf55f87f928d0d0dbbe4c9596dca220e7c8f3a9d38113837c5d09c4d8b94c5b79ae17a607644eb3228a5913c03
@@ -0,0 +1,2 @@
1
+ exclude_paths:
2
+ - "examples/**/*"
@@ -1,7 +1,7 @@
1
1
  log "logs/plum.log"
2
2
  debug false
3
3
  server_push true
4
- threaded false # create a new thread per request
4
+ threadpool_size 20 # use 20 threads to process requests (default: 1( = disable))
5
5
  fallback_legacy "127.0.0.1:8080" # forward if client doesn't support HTTP/2
6
6
 
7
7
  user "nobody"
@@ -44,7 +44,6 @@ module Plum
44
44
  ENV["RACK_ENV"] = @options[:env] if @options[:env]
45
45
  config[:debug] = @options[:debug] unless @options[:debug].nil?
46
46
  config[:server_push] = @options[:server_push] unless @options[:server_push].nil?
47
- config[:threaded] = @options[:threaded] unless @options[:threaded].nil?
48
47
  config[:threadpool_size] = @options[:threadpool_size] unless @options[:threadpool_size].nil?
49
48
 
50
49
  if @options[:fallback_legacy]
@@ -121,11 +120,7 @@ module Plum
121
120
  @options[:key] = arg
122
121
  end
123
122
 
124
- o.on "--threaded", "Call the Rack application in threads (experimental)" do
125
- @options[:threaded] = true
126
- end
127
-
128
- o.on "--threadpool-size SIZE", "Set the size of thread pool" do |arg|
123
+ o.on "--threadpool-size SIZE", "Set the size of thread pool. Set 1 to disable" do |arg|
129
124
  @options[:threadpool_size] = arg.to_i
130
125
  end
131
126
 
@@ -7,8 +7,7 @@ module Plum
7
7
  debug: false,
8
8
  log: nil, # $stdout
9
9
  server_push: true,
10
- threaded: false,
11
- threadpool_size: 20,
10
+ threadpool_size: 1,
12
11
  }.freeze
13
12
 
14
13
  def initialize(config = {})
@@ -40,10 +40,6 @@ module Plum
40
40
  @config[:server_push] = !!bool
41
41
  end
42
42
 
43
- def threaded(bool)
44
- @config[:threaded] = !!bool
45
- end
46
-
47
43
  def threadpool_size(int)
48
44
  @config[:threadpool_size] = int.to_i
49
45
  end
@@ -13,7 +13,7 @@ module Plum
13
13
 
14
14
  def run
15
15
  if @config[:fallback_legacy_host]
16
- @logger.info "legacy HTTP: fallbacking to: #{@config[:fallback_legacy_host]}:#{@config[:fallback_legacy_port]}"
16
+ @svc.logger.info "legacy HTTP: fallbacking to: #{@config[:fallback_legacy_host]}:#{@config[:fallback_legacy_port]}"
17
17
  upstream = TCPSocket.open(@config[:fallback_legacy_host], @config[:fallback_legacy_port])
18
18
  upstream.write(@e.buf) if @e.buf
19
19
  loop do
@@ -35,11 +35,11 @@ module Plum
35
35
  plum = ::Plum::HTTPServerConnection.new(sock.method(:write))
36
36
  sess = Session.new(svc, sock, plum)
37
37
  sess.run
38
- rescue Errno::ECONNRESET, EOFError # closed
39
38
  rescue ::Plum::LegacyHTTPError => e
40
- @logger.info "legacy HTTP client: #{e}"
39
+ svc.logger.info "legacy HTTP client: #{e}"
41
40
  sess = LegacySession.new(svc, e, sock)
42
41
  sess.run
42
+ rescue Errno::ECONNRESET, EOFError # closed
43
43
  rescue => e
44
44
  svc.log_exception(e)
45
45
  ensure
@@ -97,11 +97,11 @@ module Plum
97
97
  plum = ::Plum::ServerConnection.new(sock.method(:write))
98
98
  sess = Session.new(svc, sock, plum)
99
99
  sess.run
100
- rescue Errno::ECONNRESET, EOFError # closed
101
100
  rescue ::Plum::LegacyHTTPError => e
102
- @logger.info "legacy HTTP client: #{e}"
101
+ svc.logger.info "legacy HTTP client: #{e}"
103
102
  sess = LegacySession.new(svc, e, sock)
104
103
  sess.run
104
+ rescue Errno::ECONNRESET, EOFError # closed
105
105
  rescue => e
106
106
  svc.log_exception(e)
107
107
  ensure
@@ -10,7 +10,7 @@ module Plum
10
10
  @app = config[:debug] ? ::Rack::CommonLogger.new(app) : app
11
11
  @logger = Logger.new(config[:log] || $stdout).tap { |l| l.level = config[:debug] ? Logger::DEBUG : Logger::INFO }
12
12
  @listeners = config[:listeners].map { |lc| lc[:listener].new(lc) }
13
- @threadpool = ThreadPool.new(@config[:threadpool_size]) if @config[:threaded]
13
+ @threadpool = ThreadPool.new(@config[:threadpool_size]) if @config[:threadpool_size] > 1
14
14
 
15
15
  @logger.info("Plum #{::Plum::VERSION}")
16
16
  @logger.info("Config: #{config}")
@@ -51,11 +51,11 @@ module Plum
51
51
  # TODO: gracefully shutdown connections (wait threadpool?)
52
52
  end
53
53
 
54
- private
55
54
  def log_exception(e)
56
55
  @logger.error("#{e.class}: #{e.message}\n#{e.backtrace.map { |b| "\t#{b}" }.join("\n")}")
57
56
  end
58
57
 
58
+ private
59
59
  def drop_privileges
60
60
  begin
61
61
  user = @config[:user]
@@ -19,6 +19,8 @@ module Plum
19
19
  @threadpool = svc.threadpool
20
20
 
21
21
  setup_plum
22
+ rescue Errno::ENOTCONN
23
+ # TCP connection reset while doing TLS handshake
22
24
  end
23
25
 
24
26
  def stop
@@ -2,7 +2,7 @@
2
2
  module Plum
3
3
  module Rack
4
4
  class ThreadPool
5
- def initialize(size = 20)
5
+ def initialize(size)
6
6
  @workers = Set.new
7
7
  @jobs = Queue.new
8
8
 
@@ -221,11 +221,11 @@ module Plum
221
221
 
222
222
  def receive_priority_payload(payload)
223
223
  esd = payload.uint32
224
- e = esd >> 31
225
- dependency_id = e & ~(1 << 31)
224
+ e = (esd >> 31) == 1
225
+ dependency_id = esd & ~(1 << 31)
226
226
  weight = payload.uint8(4)
227
227
 
228
- update_dependency(weight: weight, parent: @connection.streams[dependency_id], exclusive: e == 1)
228
+ update_dependency(weight: weight, parent: @connection.streams[dependency_id], exclusive: e)
229
229
  end
230
230
 
231
231
  def receive_rst_stream(frame)
@@ -1,4 +1,4 @@
1
1
  # -*- frozen-string-literal: true -*-
2
2
  module Plum
3
- VERSION = "0.2.9"
3
+ VERSION = "0.2.10"
4
4
  end
@@ -15,7 +15,8 @@ module Rack
15
15
  port: opts[:Port].to_i
16
16
  }
17
17
  ],
18
- debug: !!opts[:Debug]
18
+ debug: !!opts[:Debug],
19
+ threadpool_size: opts[:Threads].to_i
19
20
  )
20
21
 
21
22
  @server = ::Plum::Rack::Server.new(app, config)
@@ -29,9 +30,10 @@ module Rack
29
30
 
30
31
  def self.valid_options
31
32
  {
32
- "Host=HOST" => "Hostname to listen on (default: #{default_options[:Host]})",
33
- "Port=PORT" => "Port to listen on (default: #{default_options[:Port]})",
34
- "Debug" => "Turn on debug mode (default: #{default_options[:Debug]})",
33
+ "Host=HOST" => "Hostname to listen on (default: #{default_options[:Host]})",
34
+ "Port=PORT" => "Port to listen on (default: #{default_options[:Port]})",
35
+ "Debug" => "Turn on debug mode (default: #{default_options[:Debug]})",
36
+ "Threads=N" => "Use N threads (default: #{default_options[:Threads]})",
35
37
  }
36
38
  end
37
39
 
@@ -43,6 +45,7 @@ module Rack
43
45
  Host: dev ? "localhost" : "0.0.0.0",
44
46
  Port: 8080,
45
47
  Debug: dev,
48
+ Threads: 20,
46
49
  }
47
50
  end
48
51
  end
@@ -192,7 +192,7 @@ class StreamHandleFrameTest < Minitest::Test
192
192
  def test_stream_handle_priority_self_depend
193
193
  open_server_connection {|con|
194
194
  stream = open_new_stream(con)
195
- payload = "".push_uint32((1 << 31) | stream.id).push_uint8(6)
195
+ payload = "".push_uint32((0 << 31) | stream.id).push_uint8(6)
196
196
  stream.receive_frame(Frame.new(type: :priority,
197
197
  stream_id: stream.id,
198
198
  payload: payload))
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: plum
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.9
4
+ version: 0.2.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - rhenium
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-01-14 00:00:00.000000000 Z
11
+ date: 2016-01-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -158,6 +158,7 @@ executables:
158
158
  extensions: []
159
159
  extra_rdoc_files: []
160
160
  files:
161
+ - ".codeclimate.yml"
161
162
  - ".gitignore"
162
163
  - ".travis.yml"
163
164
  - Gemfile