зеркало из https://github.com/github/ruby.git
webrick/httpresponse: IO.copy_stream for regular files
Remove the redundant _send_file method since its functionality is unnecessary with IO.copy_stream. IO.copy_stream also allows the use of sendfile under some OSes to speed up copies to non-TLS sockets. Testing with "curl >/dev/null" and "ruby -run -e httpd" to read a 1G file over Linux loopback reveals a reduction from around ~0.770 to ~0.490 seconds on the client side. * lib/webrick/httpresponse.rb (send_body_io): use IO.copy_stream (_send_file): remove [Feature #14237] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62954 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
Родитель
c44978b99f
Коммит
2bdcd0bdde
|
@ -410,9 +410,9 @@ module WEBrick
|
||||||
buf.clear
|
buf.clear
|
||||||
socket.write("0#{CRLF}#{CRLF}")
|
socket.write("0#{CRLF}#{CRLF}")
|
||||||
else
|
else
|
||||||
size = @header['content-length'].to_i
|
size = @header['content-length']
|
||||||
_send_file(socket, @body, 0, size)
|
size = size.to_i if size
|
||||||
@sent_size = size
|
@sent_size = IO.copy_stream(@body, socket, size)
|
||||||
end
|
end
|
||||||
ensure
|
ensure
|
||||||
@body.close
|
@body.close
|
||||||
|
@ -474,27 +474,6 @@ module WEBrick
|
||||||
alias :<< :write
|
alias :<< :write
|
||||||
end
|
end
|
||||||
|
|
||||||
def _send_file(output, input, offset, size)
|
|
||||||
while offset > 0
|
|
||||||
sz = @buffer_size < size ? @buffer_size : size
|
|
||||||
buf = input.read(sz)
|
|
||||||
offset -= buf.bytesize
|
|
||||||
end
|
|
||||||
|
|
||||||
if size == 0
|
|
||||||
while buf = input.read(@buffer_size)
|
|
||||||
output.write(buf)
|
|
||||||
end
|
|
||||||
else
|
|
||||||
while size > 0
|
|
||||||
sz = @buffer_size < size ? @buffer_size : size
|
|
||||||
buf = input.read(sz)
|
|
||||||
output.write(buf)
|
|
||||||
size -= buf.bytesize
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
# preserved for compatibility with some 3rd-party handlers
|
# preserved for compatibility with some 3rd-party handlers
|
||||||
def _write_data(socket, data)
|
def _write_data(socket, data)
|
||||||
socket << data
|
socket << data
|
||||||
|
|
Загрузка…
Ссылка в новой задаче