diff options
author | Eric Wong <normalperson@yhbt.net> | 2010-11-12 10:59:14 +0800 |
---|---|---|
committer | Eric Wong <normalperson@yhbt.net> | 2010-11-12 11:00:22 +0800 |
commit | 855c02a9720a17854a2f1c715efbe502cdba54e2 (patch) | |
tree | 52968f53cf0225a3b717c20d815e8cd1b116923c /lib/unicorn/stream_input.rb | |
parent | 3b544fb2c0e4a1e14a7bcb752a8af9819b5aaeb2 (diff) | |
download | unicorn-855c02a9720a17854a2f1c715efbe502cdba54e2.tar.gz |
Avoid having specific knowledge of internals in TeeInput and instead move that to StreamInput when dealing with byte counts. This makes things easier for Rainbows! which will need to extends these classes.
Diffstat (limited to 'lib/unicorn/stream_input.rb')
-rw-r--r-- | lib/unicorn/stream_input.rb | 24 |
1 files changed, 14 insertions, 10 deletions
diff --git a/lib/unicorn/stream_input.rb b/lib/unicorn/stream_input.rb index 2a05337..2c8e40a 100644 --- a/lib/unicorn/stream_input.rb +++ b/lib/unicorn/stream_input.rb @@ -43,15 +43,7 @@ class Unicorn::StreamInput length = args.shift rv = args.shift || '' if length.nil? - rv.replace(@rbuf) - @rbuf.replace('') - @socket or return rv - until eof? - @socket.kgio_read(@@io_chunk_size, @buf) or eof! - filter_body(@rbuf, @buf) - rv << @rbuf - end - @rbuf.replace('') + read_all(rv) else if length <= @rbuf.size rv.replace(@rbuf.slice(0, length)) @@ -85,7 +77,7 @@ class Unicorn::StreamInput def gets sep = $/ if sep.nil? - rv = read + read_all(rv = '') return rv.empty? ? nil : rv end re = /\A(.*?#{Regexp.escape(sep)})/ @@ -141,6 +133,18 @@ private rv end + def read_all(dst) + dst.replace(@rbuf) + @socket or return + until eof? + @socket.kgio_read(@@io_chunk_size, @buf) or eof! + filter_body(@rbuf, @buf) + dst << @rbuf + end + ensure + @rbuf.replace('') + end + def eof! # in case client only did a premature shutdown(SHUT_WR) # we do support clients that shutdown(SHUT_WR) after the |