puma 4.3.5 → 6.0.1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of puma might be problematic. Click here for more details.

Files changed (95) hide show
  1. checksums.yaml +4 -4
  2. data/History.md +1639 -519
  3. data/LICENSE +23 -20
  4. data/README.md +130 -42
  5. data/bin/puma-wild +3 -9
  6. data/docs/architecture.md +63 -26
  7. data/docs/compile_options.md +55 -0
  8. data/docs/deployment.md +60 -69
  9. data/docs/fork_worker.md +31 -0
  10. data/docs/images/puma-connection-flow-no-reactor.png +0 -0
  11. data/docs/images/puma-connection-flow.png +0 -0
  12. data/docs/images/puma-general-arch.png +0 -0
  13. data/docs/jungle/README.md +9 -0
  14. data/{tools → docs}/jungle/rc.d/README.md +1 -1
  15. data/{tools → docs}/jungle/rc.d/puma +2 -2
  16. data/{tools → docs}/jungle/rc.d/puma.conf +0 -0
  17. data/docs/kubernetes.md +66 -0
  18. data/docs/nginx.md +2 -2
  19. data/docs/plugins.md +15 -15
  20. data/docs/rails_dev_mode.md +28 -0
  21. data/docs/restart.md +46 -23
  22. data/docs/signals.md +13 -11
  23. data/docs/stats.md +142 -0
  24. data/docs/systemd.md +85 -128
  25. data/docs/testing_benchmarks_local_files.md +150 -0
  26. data/docs/testing_test_rackup_ci_files.md +36 -0
  27. data/ext/puma_http11/PumaHttp11Service.java +2 -4
  28. data/ext/puma_http11/ext_help.h +1 -1
  29. data/ext/puma_http11/extconf.rb +56 -11
  30. data/ext/puma_http11/http11_parser.c +69 -58
  31. data/ext/puma_http11/http11_parser.h +2 -2
  32. data/ext/puma_http11/http11_parser.java.rl +3 -3
  33. data/ext/puma_http11/http11_parser.rl +3 -3
  34. data/ext/puma_http11/http11_parser_common.rl +3 -3
  35. data/ext/puma_http11/mini_ssl.c +322 -130
  36. data/ext/puma_http11/no_ssl/PumaHttp11Service.java +15 -0
  37. data/ext/puma_http11/org/jruby/puma/Http11.java +6 -6
  38. data/ext/puma_http11/org/jruby/puma/Http11Parser.java +52 -52
  39. data/ext/puma_http11/org/jruby/puma/MiniSSL.java +241 -96
  40. data/ext/puma_http11/puma_http11.c +47 -57
  41. data/lib/puma/app/status.rb +53 -37
  42. data/lib/puma/binder.rb +232 -119
  43. data/lib/puma/cli.rb +33 -33
  44. data/lib/puma/client.rb +197 -101
  45. data/lib/puma/cluster/worker.rb +175 -0
  46. data/lib/puma/cluster/worker_handle.rb +97 -0
  47. data/lib/puma/cluster.rb +224 -229
  48. data/lib/puma/commonlogger.rb +2 -2
  49. data/lib/puma/configuration.rb +112 -87
  50. data/lib/puma/const.rb +30 -25
  51. data/lib/puma/control_cli.rb +99 -79
  52. data/lib/puma/detect.rb +31 -2
  53. data/lib/puma/dsl.rb +426 -110
  54. data/lib/puma/error_logger.rb +112 -0
  55. data/lib/puma/events.rb +16 -115
  56. data/lib/puma/io_buffer.rb +44 -2
  57. data/lib/puma/jruby_restart.rb +2 -59
  58. data/lib/puma/json_serialization.rb +96 -0
  59. data/lib/puma/launcher/bundle_pruner.rb +104 -0
  60. data/lib/puma/launcher.rb +170 -148
  61. data/lib/puma/log_writer.rb +137 -0
  62. data/lib/puma/minissl/context_builder.rb +35 -19
  63. data/lib/puma/minissl.rb +213 -55
  64. data/lib/puma/null_io.rb +18 -1
  65. data/lib/puma/plugin/tmp_restart.rb +1 -1
  66. data/lib/puma/plugin.rb +3 -12
  67. data/lib/puma/rack/builder.rb +5 -9
  68. data/lib/puma/rack/urlmap.rb +0 -0
  69. data/lib/puma/rack_default.rb +1 -1
  70. data/lib/puma/reactor.rb +85 -369
  71. data/lib/puma/request.rb +644 -0
  72. data/lib/puma/runner.rb +83 -77
  73. data/lib/puma/server.rb +303 -773
  74. data/lib/puma/single.rb +18 -74
  75. data/lib/puma/state_file.rb +45 -8
  76. data/lib/puma/systemd.rb +47 -0
  77. data/lib/puma/thread_pool.rb +136 -68
  78. data/lib/puma/util.rb +21 -4
  79. data/lib/puma.rb +54 -5
  80. data/lib/rack/handler/puma.rb +11 -12
  81. data/tools/{docker/Dockerfile → Dockerfile} +1 -1
  82. data/tools/trickletest.rb +0 -0
  83. metadata +36 -28
  84. data/docs/tcp_mode.md +0 -96
  85. data/ext/puma_http11/io_buffer.c +0 -155
  86. data/ext/puma_http11/org/jruby/puma/IOBuffer.java +0 -72
  87. data/lib/puma/accept_nonblock.rb +0 -29
  88. data/lib/puma/tcp_logger.rb +0 -41
  89. data/tools/jungle/README.md +0 -19
  90. data/tools/jungle/init.d/README.md +0 -61
  91. data/tools/jungle/init.d/puma +0 -421
  92. data/tools/jungle/init.d/run-puma +0 -18
  93. data/tools/jungle/upstart/README.md +0 -61
  94. data/tools/jungle/upstart/puma-manager.conf +0 -31
  95. data/tools/jungle/upstart/puma.conf +0 -69
data/lib/puma.rb CHANGED
@@ -10,22 +10,71 @@ require 'stringio'
10
10
 
11
11
  require 'thread'
12
12
 
13
+ # use require, see https://github.com/puma/puma/pull/2381
14
+ require 'puma/puma_http11'
15
+
16
+ require_relative 'puma/detect'
17
+ require_relative 'puma/json_serialization'
18
+
13
19
  module Puma
14
- autoload :Const, 'puma/const'
15
- autoload :Server, 'puma/server'
16
- autoload :Launcher, 'puma/launcher'
20
+ # when Puma is loaded via `Puma::CLI`, all files are loaded via
21
+ # `require_relative`. The below are for non-standard loading
22
+ autoload :Const, "#{__dir__}/puma/const"
23
+ autoload :Server, "#{__dir__}/puma/server"
24
+ autoload :Launcher, "#{__dir__}/puma/launcher"
25
+ autoload :LogWriter, "#{__dir__}/puma/log_writer"
26
+
27
+ # at present, MiniSSL::Engine is only defined in extension code (puma_http11),
28
+ # not in minissl.rb
29
+ HAS_SSL = const_defined?(:MiniSSL, false) && MiniSSL.const_defined?(:Engine, false)
30
+
31
+ HAS_UNIX_SOCKET = Object.const_defined?(:UNIXSocket) && !IS_WINDOWS
32
+
33
+ if HAS_SSL
34
+ require_relative 'puma/minissl'
35
+ else
36
+ module MiniSSL
37
+ # this class is defined so that it exists when Puma is compiled
38
+ # without ssl support, as Server and Reactor use it in rescue statements.
39
+ class SSLError < StandardError ; end
40
+ end
41
+ end
17
42
 
43
+ def self.ssl?
44
+ HAS_SSL
45
+ end
46
+
47
+ def self.abstract_unix_socket?
48
+ @abstract_unix ||=
49
+ if HAS_UNIX_SOCKET
50
+ begin
51
+ ::UNIXServer.new("\0puma.temp.unix").close
52
+ true
53
+ rescue ArgumentError # darwin
54
+ false
55
+ end
56
+ else
57
+ false
58
+ end
59
+ end
60
+
61
+ # @!attribute [rw] stats_object=
18
62
  def self.stats_object=(val)
19
63
  @get_stats = val
20
64
  end
21
65
 
66
+ # @!attribute [rw] stats_object
22
67
  def self.stats
68
+ Puma::JSONSerialization.generate @get_stats.stats
69
+ end
70
+
71
+ # @!attribute [r] stats_hash
72
+ # @version 5.0.0
73
+ def self.stats_hash
23
74
  @get_stats.stats
24
75
  end
25
76
 
26
- # Thread name is new in Ruby 2.3
27
77
  def self.set_thread_name(name)
28
- return unless Thread.current.respond_to?(:name=)
29
78
  Thread.current.name = "puma #{name}"
30
79
  end
31
80
  end
@@ -11,10 +11,10 @@ module Rack
11
11
  }
12
12
 
13
13
  def self.config(app, options = {})
14
- require 'puma'
15
- require 'puma/configuration'
16
- require 'puma/events'
17
- require 'puma/launcher'
14
+ require_relative '../../puma'
15
+ require_relative '../../puma/configuration'
16
+ require_relative '../../puma/log_writer'
17
+ require_relative '../../puma/launcher'
18
18
 
19
19
  default_options = DEFAULT_OPTIONS.dup
20
20
 
@@ -30,9 +30,8 @@ module Rack
30
30
  end
31
31
 
32
32
  conf = ::Puma::Configuration.new(options, default_options) do |user_config, file_config, default_config|
33
- user_config.quiet
34
-
35
33
  if options.delete(:Verbose)
34
+ require 'rack/common_logger'
36
35
  app = Rack::CommonLogger.new(app, STDOUT)
37
36
  end
38
37
 
@@ -61,12 +60,12 @@ module Rack
61
60
  conf
62
61
  end
63
62
 
64
- def self.run(app, options = {})
63
+ def self.run(app, **options)
65
64
  conf = self.config(app, options)
66
65
 
67
- events = options.delete(:Silent) ? ::Puma::Events.strings : ::Puma::Events.stdio
66
+ log_writer = options.delete(:Silent) ? ::Puma::LogWriter.strings : ::Puma::LogWriter.stdio
68
67
 
69
- launcher = ::Puma::Launcher.new(conf, :events => events)
68
+ launcher = ::Puma::Launcher.new(conf, :log_writer => log_writer)
70
69
 
71
70
  yield launcher if block_given?
72
71
  begin
@@ -94,16 +93,16 @@ module Rack
94
93
  config.bind "unix://#{host}"
95
94
  elsif host && host =~ /^ssl:\/\//
96
95
  uri = URI.parse(host)
97
- uri.port ||= port || ::Puma::Configuration::DefaultTCPPort
96
+ uri.port ||= port || ::Puma::Configuration::DEFAULTS[:tcp_port]
98
97
  config.bind uri.to_s
99
98
  else
100
99
 
101
100
  if host
102
- port ||= ::Puma::Configuration::DefaultTCPPort
101
+ port ||= ::Puma::Configuration::DEFAULTS[:tcp_port]
103
102
  end
104
103
 
105
104
  if port
106
- host ||= ::Puma::Configuration::DefaultTCPHost
105
+ host ||= ::Puma::Configuration::DEFAULTS[:tcp_host]
107
106
  config.port port, host
108
107
  end
109
108
  end
@@ -1,6 +1,6 @@
1
1
  # Use this Dockerfile to create minimal reproductions of issues
2
2
 
3
- FROM ruby:2.6
3
+ FROM ruby:3.1
4
4
 
5
5
  # throw errors if Gemfile has been modified since Gemfile.lock
6
6
  RUN bundle config --global frozen 1
data/tools/trickletest.rb CHANGED
File without changes
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: puma
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.3.5
4
+ version: 6.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Evan Phoenix
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-05-19 00:00:00.000000000 Z
11
+ date: 1980-01-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nio4r
@@ -24,9 +24,9 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '2.0'
27
- description: Puma is a simple, fast, threaded, and highly concurrent HTTP 1.1 server
27
+ description: Puma is a simple, fast, threaded, and highly parallel HTTP 1.1 server
28
28
  for Ruby/Rack applications. Puma is intended for use in both development and production
29
- environments. It's great for highly concurrent Ruby implementations such as Rubinius
29
+ environments. It's great for highly parallel Ruby implementations such as Rubinius
30
30
  and JRuby as well as as providing process worker support to support CRuby well.
31
31
  email:
32
32
  - evan@phx.io
@@ -44,16 +44,26 @@ files:
44
44
  - bin/puma-wild
45
45
  - bin/pumactl
46
46
  - docs/architecture.md
47
+ - docs/compile_options.md
47
48
  - docs/deployment.md
49
+ - docs/fork_worker.md
48
50
  - docs/images/puma-connection-flow-no-reactor.png
49
51
  - docs/images/puma-connection-flow.png
50
52
  - docs/images/puma-general-arch.png
53
+ - docs/jungle/README.md
54
+ - docs/jungle/rc.d/README.md
55
+ - docs/jungle/rc.d/puma
56
+ - docs/jungle/rc.d/puma.conf
57
+ - docs/kubernetes.md
51
58
  - docs/nginx.md
52
59
  - docs/plugins.md
60
+ - docs/rails_dev_mode.md
53
61
  - docs/restart.md
54
62
  - docs/signals.md
63
+ - docs/stats.md
55
64
  - docs/systemd.md
56
- - docs/tcp_mode.md
65
+ - docs/testing_benchmarks_local_files.md
66
+ - docs/testing_test_rackup_ci_files.md
57
67
  - ext/puma_http11/PumaHttp11Service.java
58
68
  - ext/puma_http11/ext_help.h
59
69
  - ext/puma_http11/extconf.rb
@@ -62,30 +72,34 @@ files:
62
72
  - ext/puma_http11/http11_parser.java.rl
63
73
  - ext/puma_http11/http11_parser.rl
64
74
  - ext/puma_http11/http11_parser_common.rl
65
- - ext/puma_http11/io_buffer.c
66
75
  - ext/puma_http11/mini_ssl.c
76
+ - ext/puma_http11/no_ssl/PumaHttp11Service.java
67
77
  - ext/puma_http11/org/jruby/puma/Http11.java
68
78
  - ext/puma_http11/org/jruby/puma/Http11Parser.java
69
- - ext/puma_http11/org/jruby/puma/IOBuffer.java
70
79
  - ext/puma_http11/org/jruby/puma/MiniSSL.java
71
80
  - ext/puma_http11/puma_http11.c
72
81
  - lib/puma.rb
73
- - lib/puma/accept_nonblock.rb
74
82
  - lib/puma/app/status.rb
75
83
  - lib/puma/binder.rb
76
84
  - lib/puma/cli.rb
77
85
  - lib/puma/client.rb
78
86
  - lib/puma/cluster.rb
87
+ - lib/puma/cluster/worker.rb
88
+ - lib/puma/cluster/worker_handle.rb
79
89
  - lib/puma/commonlogger.rb
80
90
  - lib/puma/configuration.rb
81
91
  - lib/puma/const.rb
82
92
  - lib/puma/control_cli.rb
83
93
  - lib/puma/detect.rb
84
94
  - lib/puma/dsl.rb
95
+ - lib/puma/error_logger.rb
85
96
  - lib/puma/events.rb
86
97
  - lib/puma/io_buffer.rb
87
98
  - lib/puma/jruby_restart.rb
99
+ - lib/puma/json_serialization.rb
88
100
  - lib/puma/launcher.rb
101
+ - lib/puma/launcher/bundle_pruner.rb
102
+ - lib/puma/log_writer.rb
89
103
  - lib/puma/minissl.rb
90
104
  - lib/puma/minissl/context_builder.rb
91
105
  - lib/puma/null_io.rb
@@ -95,33 +109,27 @@ files:
95
109
  - lib/puma/rack/urlmap.rb
96
110
  - lib/puma/rack_default.rb
97
111
  - lib/puma/reactor.rb
112
+ - lib/puma/request.rb
98
113
  - lib/puma/runner.rb
99
114
  - lib/puma/server.rb
100
115
  - lib/puma/single.rb
101
116
  - lib/puma/state_file.rb
102
- - lib/puma/tcp_logger.rb
117
+ - lib/puma/systemd.rb
103
118
  - lib/puma/thread_pool.rb
104
119
  - lib/puma/util.rb
105
120
  - lib/rack/handler/puma.rb
106
- - tools/docker/Dockerfile
107
- - tools/jungle/README.md
108
- - tools/jungle/init.d/README.md
109
- - tools/jungle/init.d/puma
110
- - tools/jungle/init.d/run-puma
111
- - tools/jungle/rc.d/README.md
112
- - tools/jungle/rc.d/puma
113
- - tools/jungle/rc.d/puma.conf
114
- - tools/jungle/upstart/README.md
115
- - tools/jungle/upstart/puma-manager.conf
116
- - tools/jungle/upstart/puma.conf
121
+ - tools/Dockerfile
117
122
  - tools/trickletest.rb
118
- homepage: http://puma.io
123
+ homepage: https://puma.io
119
124
  licenses:
120
125
  - BSD-3-Clause
121
126
  metadata:
122
- msys2_mingw_dependencies: openssl
127
+ bug_tracker_uri: https://github.com/puma/puma/issues
123
128
  changelog_uri: https://github.com/puma/puma/blob/master/History.md
124
- post_install_message:
129
+ homepage_uri: https://puma.io
130
+ source_code_uri: https://github.com/puma/puma
131
+ rubygems_mfa_required: 'true'
132
+ post_install_message:
125
133
  rdoc_options: []
126
134
  require_paths:
127
135
  - lib
@@ -129,16 +137,16 @@ required_ruby_version: !ruby/object:Gem::Requirement
129
137
  requirements:
130
138
  - - ">="
131
139
  - !ruby/object:Gem::Version
132
- version: '2.2'
140
+ version: '2.4'
133
141
  required_rubygems_version: !ruby/object:Gem::Requirement
134
142
  requirements:
135
143
  - - ">="
136
144
  - !ruby/object:Gem::Version
137
145
  version: '0'
138
146
  requirements: []
139
- rubygems_version: 3.0.3
140
- signing_key:
147
+ rubygems_version: 3.2.26
148
+ signing_key:
141
149
  specification_version: 4
142
- summary: Puma is a simple, fast, threaded, and highly concurrent HTTP 1.1 server for
150
+ summary: Puma is a simple, fast, threaded, and highly parallel HTTP 1.1 server for
143
151
  Ruby/Rack applications
144
152
  test_files: []
data/docs/tcp_mode.md DELETED
@@ -1,96 +0,0 @@
1
- # TCP mode
2
-
3
- Puma also could be used as a TCP server to process incoming TCP
4
- connections.
5
-
6
-
7
- ## Configuration
8
-
9
- TCP mode can be enabled with CLI option `--tcp-mode`:
10
-
11
- ```
12
- $ puma --tcp-mode
13
- ```
14
-
15
- Default ip and port to listen to are `0.0.0.0` and `9292`. You can configure
16
- them with `--port` and `--bind` options:
17
-
18
- ```
19
- $ puma --tcp-mode --bind tcp://127.0.0.1:9293
20
- $ puma --tcp-mode --port 9293
21
- ```
22
-
23
- TCP mode could be set with a configuration file as well with `tcp_mode`
24
- and `tcp_mode!` methods:
25
-
26
- ```
27
- # config/puma.rb
28
- tcp_mode
29
- ```
30
-
31
- When Puma starts in the TCP mode it prints the corresponding message:
32
-
33
- ```
34
- puma --tcp-mode
35
- Puma starting in single mode...
36
- ...
37
- * Mode: Lopez Express (tcp)
38
- ```
39
-
40
-
41
- ## How to declare an application
42
-
43
- An application to process TCP connections should be declared as a
44
- callable object which accepts `env` and `socket` arguments.
45
-
46
- `env` argument is a Hash with following structure:
47
-
48
- ```ruby
49
- { "thread" => {}, "REMOTE_ADDR" => "127.0.0.1:51133", "log" => "#<Proc:0x000..." }
50
- ```
51
-
52
- It consists of:
53
- * `thread` - a Hash for each thread in the thread pool that could be
54
- used to store information between requests
55
- * `REMOTE_ADDR` - a client ip address
56
- * `log` - a proc object to write something down
57
-
58
- `log` object could be used this way:
59
-
60
- ```ruby
61
- env['log'].call('message to log')
62
- #> 19/Oct/2019 20:28:53 - 127.0.0.1:51266 - message to log
63
- ```
64
-
65
-
66
- ## Example of an application
67
-
68
- Let's look at an example of a simple application which just echoes
69
- incoming string:
70
-
71
- ```ruby
72
- # config/puma.rb
73
- app do |env, socket|
74
- s = socket.gets
75
- socket.puts "Echo #{s}"
76
- end
77
- ```
78
-
79
- We can easily access the TCP server with `telnet` command and receive an
80
- echo:
81
-
82
- ```shell
83
- telnet 0.0.0.0 9293
84
- Trying 0.0.0.0...
85
- Connected to 0.0.0.0.
86
- Escape character is '^]'.
87
- sssss
88
- Echo sssss
89
- ^CConnection closed by foreign host.
90
- ```
91
-
92
-
93
- ## Socket management
94
-
95
- After the application finishes, Puma closes the socket. In order to
96
- prevent this, the application should set `env['detach'] = true`.
@@ -1,155 +0,0 @@
1
- #define RSTRING_NOT_MODIFIED 1
2
- #include "ruby.h"
3
-
4
- #include <sys/types.h>
5
-
6
- struct buf_int {
7
- uint8_t* top;
8
- uint8_t* cur;
9
-
10
- size_t size;
11
- };
12
-
13
- #define BUF_DEFAULT_SIZE 4096
14
- #define BUF_TOLERANCE 32
15
-
16
- static void buf_free(struct buf_int* internal) {
17
- xfree(internal->top);
18
- xfree(internal);
19
- }
20
-
21
- static VALUE buf_alloc(VALUE self) {
22
- VALUE buf;
23
- struct buf_int* internal;
24
-
25
- buf = Data_Make_Struct(self, struct buf_int, 0, buf_free, internal);
26
-
27
- internal->size = BUF_DEFAULT_SIZE;
28
- internal->top = ALLOC_N(uint8_t, BUF_DEFAULT_SIZE);
29
- internal->cur = internal->top;
30
-
31
- return buf;
32
- }
33
-
34
- static VALUE buf_append(VALUE self, VALUE str) {
35
- struct buf_int* b;
36
- size_t used, str_len, new_size;
37
-
38
- Data_Get_Struct(self, struct buf_int, b);
39
-
40
- used = b->cur - b->top;
41
-
42
- StringValue(str);
43
- str_len = RSTRING_LEN(str);
44
-
45
- new_size = used + str_len;
46
-
47
- if(new_size > b->size) {
48
- size_t n = b->size + (b->size / 2);
49
- uint8_t* top;
50
- uint8_t* old;
51
-
52
- new_size = (n > new_size ? n : new_size + BUF_TOLERANCE);
53
-
54
- top = ALLOC_N(uint8_t, new_size);
55
- old = b->top;
56
- memcpy(top, old, used);
57
- b->top = top;
58
- b->cur = top + used;
59
- b->size = new_size;
60
- xfree(old);
61
- }
62
-
63
- memcpy(b->cur, RSTRING_PTR(str), str_len);
64
- b->cur += str_len;
65
-
66
- return self;
67
- }
68
-
69
- static VALUE buf_append2(int argc, VALUE* argv, VALUE self) {
70
- struct buf_int* b;
71
- size_t used, new_size;
72
- int i;
73
- VALUE str;
74
-
75
- Data_Get_Struct(self, struct buf_int, b);
76
-
77
- used = b->cur - b->top;
78
- new_size = used;
79
-
80
- for(i = 0; i < argc; i++) {
81
- StringValue(argv[i]);
82
-
83
- str = argv[i];
84
-
85
- new_size += RSTRING_LEN(str);
86
- }
87
-
88
- if(new_size > b->size) {
89
- size_t n = b->size + (b->size / 2);
90
- uint8_t* top;
91
- uint8_t* old;
92
-
93
- new_size = (n > new_size ? n : new_size + BUF_TOLERANCE);
94
-
95
- top = ALLOC_N(uint8_t, new_size);
96
- old = b->top;
97
- memcpy(top, old, used);
98
- b->top = top;
99
- b->cur = top + used;
100
- b->size = new_size;
101
- xfree(old);
102
- }
103
-
104
- for(i = 0; i < argc; i++) {
105
- long str_len;
106
- str = argv[i];
107
- str_len = RSTRING_LEN(str);
108
- memcpy(b->cur, RSTRING_PTR(str), str_len);
109
- b->cur += str_len;
110
- }
111
-
112
- return self;
113
- }
114
-
115
- static VALUE buf_to_str(VALUE self) {
116
- struct buf_int* b;
117
- Data_Get_Struct(self, struct buf_int, b);
118
-
119
- return rb_str_new((const char*)(b->top), b->cur - b->top);
120
- }
121
-
122
- static VALUE buf_used(VALUE self) {
123
- struct buf_int* b;
124
- Data_Get_Struct(self, struct buf_int, b);
125
-
126
- return INT2FIX(b->cur - b->top);
127
- }
128
-
129
- static VALUE buf_capa(VALUE self) {
130
- struct buf_int* b;
131
- Data_Get_Struct(self, struct buf_int, b);
132
-
133
- return INT2FIX(b->size);
134
- }
135
-
136
- static VALUE buf_reset(VALUE self) {
137
- struct buf_int* b;
138
- Data_Get_Struct(self, struct buf_int, b);
139
-
140
- b->cur = b->top;
141
- return self;
142
- }
143
-
144
- void Init_io_buffer(VALUE puma) {
145
- VALUE buf = rb_define_class_under(puma, "IOBuffer", rb_cObject);
146
-
147
- rb_define_alloc_func(buf, buf_alloc);
148
- rb_define_method(buf, "<<", buf_append, 1);
149
- rb_define_method(buf, "append", buf_append2, -1);
150
- rb_define_method(buf, "to_str", buf_to_str, 0);
151
- rb_define_method(buf, "to_s", buf_to_str, 0);
152
- rb_define_method(buf, "used", buf_used, 0);
153
- rb_define_method(buf, "capacity", buf_capa, 0);
154
- rb_define_method(buf, "reset", buf_reset, 0);
155
- }
@@ -1,72 +0,0 @@
1
- package org.jruby.puma;
2
-
3
- import org.jruby.*;
4
- import org.jruby.anno.JRubyMethod;
5
- import org.jruby.runtime.ObjectAllocator;
6
- import org.jruby.runtime.ThreadContext;
7
- import org.jruby.runtime.builtin.IRubyObject;
8
- import org.jruby.util.ByteList;
9
-
10
- /**
11
- * @author kares
12
- */
13
- public class IOBuffer extends RubyObject {
14
-
15
- private static final ObjectAllocator ALLOCATOR = new ObjectAllocator() {
16
- public IRubyObject allocate(Ruby runtime, RubyClass klass) {
17
- return new IOBuffer(runtime, klass);
18
- }
19
- };
20
-
21
- public static void createIOBuffer(Ruby runtime) {
22
- RubyModule mPuma = runtime.defineModule("Puma");
23
- RubyClass cIOBuffer = mPuma.defineClassUnder("IOBuffer", runtime.getObject(), ALLOCATOR);
24
- cIOBuffer.defineAnnotatedMethods(IOBuffer.class);
25
- }
26
-
27
- private static final int DEFAULT_SIZE = 4096;
28
-
29
- final ByteList buffer = new ByteList(DEFAULT_SIZE);
30
-
31
- IOBuffer(Ruby runtime, RubyClass klass) {
32
- super(runtime, klass);
33
- }
34
-
35
- @JRubyMethod
36
- public RubyInteger used(ThreadContext context) {
37
- return context.runtime.newFixnum(buffer.getRealSize());
38
- }
39
-
40
- @JRubyMethod
41
- public RubyInteger capacity(ThreadContext context) {
42
- return context.runtime.newFixnum(buffer.unsafeBytes().length);
43
- }
44
-
45
- @JRubyMethod
46
- public IRubyObject reset() {
47
- buffer.setRealSize(0);
48
- return this;
49
- }
50
-
51
- @JRubyMethod(name = { "to_s", "to_str" })
52
- public RubyString to_s(ThreadContext context) {
53
- return RubyString.newStringShared(context.runtime, buffer.unsafeBytes(), 0, buffer.getRealSize());
54
- }
55
-
56
- @JRubyMethod(name = "<<")
57
- public IRubyObject add(IRubyObject str) {
58
- addImpl(str.convertToString());
59
- return this;
60
- }
61
-
62
- @JRubyMethod(rest = true)
63
- public IRubyObject append(IRubyObject[] strs) {
64
- for (IRubyObject str : strs) addImpl(str.convertToString());
65
- return this;
66
- }
67
-
68
- private void addImpl(RubyString str) {
69
- buffer.append(str.getByteList());
70
- }
71
-
72
- }
@@ -1,29 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'openssl'
4
-
5
- module OpenSSL
6
- module SSL
7
- class SSLServer
8
- unless public_method_defined? :accept_nonblock
9
- def accept_nonblock
10
- sock = @svr.accept_nonblock
11
-
12
- begin
13
- ssl = OpenSSL::SSL::SSLSocket.new(sock, @ctx)
14
- ssl.sync_close = true
15
- ssl.accept if @start_immediately
16
- ssl
17
- rescue SSLError => ex
18
- if ssl
19
- ssl.close
20
- else
21
- sock.close
22
- end
23
- raise ex
24
- end
25
- end
26
- end
27
- end
28
- end
29
- end
@@ -1,41 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Puma
4
- class TCPLogger
5
- def initialize(logger, app, quiet=false)
6
- @logger = logger
7
- @app = app
8
- @quiet = quiet
9
- end
10
-
11
- FORMAT = "%s - %s"
12
-
13
- def log(who, str)
14
- now = Time.now.strftime("%d/%b/%Y %H:%M:%S")
15
-
16
- log_str = "#{now} - #{who} - #{str}"
17
-
18
- case @logger
19
- when IO
20
- @logger.puts log_str
21
- when Events
22
- @logger.log log_str
23
- end
24
- end
25
-
26
- def call(env, socket)
27
- who = env[Const::REMOTE_ADDR]
28
- log who, "connected" unless @quiet
29
-
30
- env['log'] = lambda { |str| log(who, str) }
31
-
32
- begin
33
- @app.call env, socket
34
- rescue Object => e
35
- log who, "exception: #{e.message} (#{e.class})"
36
- else
37
- log who, "disconnected" unless @quiet
38
- end
39
- end
40
- end
41
- end