X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Runtime.git;a=blobdiff_plain;f=lib%2FCatalyst%2FEngine.pm;h=347f78181c31aeab3cff9100588f0ad8320b077d;hp=0f801aa711f85439c3921148b69ec5719ef77b6d;hb=e512dd249ef1911d256f91f39ea5beaad85f73a9;hpb=bba13f350e550b180357d24e478ab120642d1d71 diff --git a/lib/Catalyst/Engine.pm b/lib/Catalyst/Engine.pm index 0f801aa..347f781 100644 --- a/lib/Catalyst/Engine.pm +++ b/lib/Catalyst/Engine.pm @@ -4,6 +4,7 @@ use strict; use base 'Class::Accessor::Fast'; use CGI::Simple::Cookie; use Data::Dump qw/dump/; +use Errno 'EWOULDBLOCK'; use HTML::Entities; use HTTP::Body; use HTTP::Headers; @@ -609,7 +610,7 @@ sub run { } =head2 $self->write($c, $buffer) -Writes the buffer to the client. Can only be called once for a request. +Writes the buffer to the client. =cut @@ -620,8 +621,27 @@ sub write { $self->prepare_write($c); $self->{_prepared_write} = 1; } - - print STDOUT $buffer; + + my $len = length($buffer); + my $wrote = syswrite STDOUT, $buffer; + + if ( defined $wrote && $wrote < $len ) { + # We didn't write the whole buffer + while (1) { + my $ret = syswrite STDOUT, $buffer, $CHUNKSIZE, $wrote; + if ( defined $ret ) { + $wrote += $ret; + } + else { + next if $! == EWOULDBLOCK; + return; + } + + last if $wrote >= $len; + } + } + + return $wrote; } =head2 $self->unescape_uri($uri)