From 07b64755b203d9c99a59ae69e3155103d4cfefc5 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Sun, 26 May 2019 22:15:44 +0000 Subject: remove kgio from all read(2) and write(2) wrappers It's fairly easy given unicorn was designed with synchronous I/O in mind. The overhead of backtraces from EOFError on readpartial should be rare given our requirement to only accept requests from fast, reliable clients on LAN (e.g. nginx or yet-another-horribly-named-server). --- lib/unicorn/stream_input.rb | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) (limited to 'lib/unicorn/stream_input.rb') diff --git a/lib/unicorn/stream_input.rb b/lib/unicorn/stream_input.rb index 41d28a0..9246f73 100644 --- a/lib/unicorn/stream_input.rb +++ b/lib/unicorn/stream_input.rb @@ -49,8 +49,7 @@ class Unicorn::StreamInput to_read = length - @rbuf.size rv.replace(@rbuf.slice!(0, @rbuf.size)) until to_read == 0 || eof? || (rv.size > 0 && @chunked) - @socket.kgio_read(to_read, @buf) or eof! - filter_body(@rbuf, @buf) + filter_body(@rbuf, @socket.readpartial(to_read, @buf)) rv << @rbuf to_read -= @rbuf.size end @@ -61,6 +60,8 @@ class Unicorn::StreamInput read_all(rv) end rv + rescue EOFError + return eof! end # :call-seq: @@ -83,9 +84,10 @@ class Unicorn::StreamInput begin @rbuf.sub!(re, '') and return $1 return @rbuf.empty? ? nil : @rbuf.slice!(0, @rbuf.size) if eof? - @socket.kgio_read(@@io_chunk_size, @buf) or eof! - filter_body(once = '', @buf) + filter_body(once = '', @socket.readpartial(@@io_chunk_size, @buf)) @rbuf << once + rescue EOFError + return eof! end while true end @@ -107,14 +109,15 @@ private def eof? if @parser.body_eof? while @chunked && ! @parser.parse - once = @socket.kgio_read(@@io_chunk_size) or eof! - @buf << once + @buf << @socket.readpartial(@@io_chunk_size) end @socket = nil true else false end + rescue EOFError + return eof! end def filter_body(dst, src) @@ -127,10 +130,11 @@ private dst.replace(@rbuf) @socket or return until eof? - @socket.kgio_read(@@io_chunk_size, @buf) or eof! - filter_body(@rbuf, @buf) + filter_body(@rbuf, @socket.readpartial(@@io_chunk_size, @buf)) dst << @rbuf end + rescue EOFError + return eof! ensure @rbuf.clear end -- cgit v1.2.3-24-ge0c7