Skip to content

Commit

Permalink
IOBuffer back to Ruby (puma#1980)
Browse files Browse the repository at this point in the history
  • Loading branch information
nateberkopec committed Feb 27, 2020
1 parent a647a9a commit 510f39d
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 241 deletions.
1 change: 1 addition & 0 deletions History.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
* Remove unused loader argument from Plugin initializer (#2095)
* Simplify `Configuration.random_token` and remove insecure fallback (#2102)
* Simplify `Runner#start_control` URL parsing (#2111)
* Removed the IOBuffer extension and replaced with Ruby (#1980)

## 4.3.2 and 3.12.3 / 2020-02-27

Expand Down
5 changes: 2 additions & 3 deletions ext/puma_http11/PumaHttp11Service.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
package puma;

import java.io.IOException;

import org.jruby.Ruby;
import org.jruby.runtime.load.BasicLibraryService;

import org.jruby.puma.Http11;
import org.jruby.puma.IOBuffer;
import org.jruby.puma.MiniSSL;

public class PumaHttp11Service implements BasicLibraryService {
public class PumaHttp11Service implements BasicLibraryService {
public boolean basicLoad(final Ruby runtime) throws IOException {
Http11.createHttp11(runtime);
IOBuffer.createIOBuffer(runtime);
MiniSSL.createMiniSSL(runtime);
return true;
}
Expand Down
155 changes: 0 additions & 155 deletions ext/puma_http11/io_buffer.c

This file was deleted.

72 changes: 0 additions & 72 deletions ext/puma_http11/org/jruby/puma/IOBuffer.java

This file was deleted.

2 changes: 0 additions & 2 deletions ext/puma_http11/puma_http11.c
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,6 @@ VALUE HttpParser_body(VALUE self) {
return http->body;
}

void Init_io_buffer(VALUE puma);
void Init_mini_ssl(VALUE mod);

void Init_puma_http11()
Expand Down Expand Up @@ -464,6 +463,5 @@ void Init_puma_http11()
rb_define_method(cHttpParser, "body", HttpParser_body, 0);
init_common_fields();

Init_io_buffer(mPuma);
Init_mini_ssl(mPuma);
}
11 changes: 9 additions & 2 deletions lib/puma/io_buffer.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
# frozen_string_literal: true

require 'puma/detect'
require 'puma/puma_http11'
module Puma
class IOBuffer < String
def append(*args)
args.each { |a| concat(a) }
end

alias reset clear
end
end
3 changes: 2 additions & 1 deletion lib/puma/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
require 'puma/binder'
require 'puma/accept_nonblock'
require 'puma/util'
require 'puma/io_buffer'

require 'puma/puma_http11'

Expand Down Expand Up @@ -297,7 +298,7 @@ def run(background=true)

@thread_pool = ThreadPool.new(@min_threads,
@max_threads,
IOBuffer) do |client, buffer|
::Puma::IOBuffer) do |client, buffer|

# Advertise this server into the thread
Thread.current[ThreadLocalKey] = self
Expand Down
10 changes: 4 additions & 6 deletions test/test_iobuffer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,29 @@ def setup
end

def test_initial_size
assert_equal 0, iobuf.used
assert iobuf.capacity > 0
assert_equal 0, iobuf.size
end

def test_append_op
iobuf << "abc"
assert_equal "abc", iobuf.to_s
iobuf << "123"
assert_equal "abc123", iobuf.to_s
assert_equal 6, iobuf.used
assert_equal 6, iobuf.size
end

def test_append
expected = "mary had a little lamb"
iobuf.append("mary", " ", "had ", "a little", " lamb")
assert_equal expected, iobuf.to_s
assert_equal expected.length, iobuf.used
assert_equal expected.length, iobuf.size
end

def test_reset
iobuf << "content"
assert_equal "content", iobuf.to_s
iobuf.reset
assert_equal 0, iobuf.used
assert_equal 0, iobuf.size
assert_equal "", iobuf.to_s
end

end

0 comments on commit 510f39d

Please sign in to comment.