X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FCatalyst%2FEngine.pm;h=089a9595412c230c9a2e051392945328c51c7b8a;hb=de19de2e6f40d9f8986df5e4f37dc8084a7c83ee;hp=0f801aa711f85439c3921148b69ec5719ef77b6d;hpb=878b821cd4548d9d3f5a6c5aa05fb2f0c29fe3b0;p=catagits%2FCatalyst-Runtime.git diff --git a/lib/Catalyst/Engine.pm b/lib/Catalyst/Engine.pm index 0f801aa..089a959 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,32 @@ 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 && $! == EWOULDBLOCK ) { + # Unable to write on the first try, will retry in the loop below + $wrote = 0; + } + + 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) @@ -633,10 +658,9 @@ as Apache may implement this using Apache's C-based modules, for example. sub unescape_uri { my ( $self, $str ) = @_; - - $str =~ s/%([0-9A-Fa-f]{2})/chr(hex($1))/eg; - $str =~ s/\+/ /g; - + + $str =~ s/(?:%([0-9A-Fa-f]{2})|\+)/defined $1 ? chr(hex($1)) : ' '/eg; + return $str; }