develooper Front page | perl.libwww | Postings from August 2001

[PATCH] Resolve "Short Write"

Thread Next
From:
Norton Allen
Date:
August 7, 2001 10:25
Subject:
[PATCH] Resolve "Short Write"
Message ID:
200108071734.NAA00829@bottesini.harvard.edu
The "short write" error reported by http.pm is a shorthand for
"Your operating system has exploited a perfectly legal feature
that apparently has not been encountered in other operating
systems to date." That feature is the possibility that syswrite
might return having only written part of the requested record,
and I have encountered it under QNX4 for file sizes in excess
of 10K bytes. This patch does the obvious loop to write out the
rest.

  -Norton Allen

*** ../ORIG/libwww-perl-5.53/lib/LWP/Protocol/http.pm	Fri Apr  6 22:13:25 2001
--- libwww-perl-5.53/lib/LWP/Protocol/http.pm	Tue Aug  7 13:26:29 2001
***************
*** 173,182 ****
  	}
      }
      elsif (defined($$cont_ref) && length($$cont_ref)) {
! 	die "write timeout" if $timeout && !$sel->can_write($timeout);
! 	$n = $socket->syswrite($$cont_ref, length($$cont_ref));
! 	die $! unless defined($n);
! 	die "short write" unless $n == length($$cont_ref);
  	LWP::Debug::conns($buf);
      }
  
--- 173,186 ----
  	}
      }
      elsif (defined($$cont_ref) && length($$cont_ref)) {
! 	my $offset = 0;
! 	my $length = length($$cont_ref);
! 	while ( $offset < $length ) {
! 	    die "write timeout" if $timeout && !$sel->can_write($timeout);
! 	    $n = $socket->syswrite($$cont_ref, $length-$offset, $offset );
! 	    die $! unless defined($n);
! 	    $offset += $n;
! 	}
  	LWP::Debug::conns($buf);
      }
  

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About