Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Ticket #4907 (closed defect: fixed)

Opened 2 years ago

Last modified 2 years ago

[PATCH] Use #flush between switching from #write to #syswrite

Reported by: Blair Zajac <blair@orcaware.com> Assigned to: David
Priority: normal Milestone:
Component: ActionPack Version: 1.1.1
Severity: normal Keywords:
Cc:

Description

In actionpack/lib/action_controller/cgi_process.rb there's this code which uses #write to send the output to the client.

    def out(output = $stdout)
      convert_content_type!(@headers)
      output.binmode      if output.respond_to?(:binmode)
      output.sync = false if output.respond_to?(:sync=)

      begin
        output.write(@cgi.header(@headers))

        if @cgi.send(:env_table)['REQUEST_METHOD'] == 'HEAD'
          return
        elsif @body.respond_to?(:call)
          output.flush if output.respond_to?(:flush)
          @body.call(self, output)

In actionpack/lib/action_controller/streaming.rb #syswrite will be used if it is available, thereby switching from #write to #syswrite

{{

File.open(path, 'rb') do |file|

if output.respond_to?(:syswrite)

begin

while true

output.syswrite(file.sysread(len))

end

rescue EOFError end

}}

At least in working with C code and stdio, you don't want to switch between fwrite() and write() without flushing.

The following patch forces a flush if a Proc is given, just to be on the safe side.

Attachments

ror-flush-out-before-proc-call.txt (0.6 kB) - added by blair on 04/27/06 02:45:20.

Change History

04/27/06 02:45:20 changed by blair

  • attachment ror-flush-out-before-proc-call.txt added.

04/29/06 05:06:51 changed by marcel

  • status changed from new to closed.
  • resolution set to fixed.

(In [4306]) Use #flush between switching from #write to #syswrite. Closes #4907. [Blair Zajac <blair@orcaware.com>]