home *** CD-ROM | disk | FTP | other *** search
/ CLIX - Fazer Clix Custa Nix / CLIX-CD.cdr / mac / lib / auto / LWP / IO / read.al < prev    next >
Text File  |  1997-12-13  |  802b  |  34 lines

  1. # NOTE: Derived from :lib:LWP:IO.pm.  Changes made here will be lost.
  2. package LWP::IO;
  3.  
  4. sub read
  5. {
  6.     my $fd      = shift;
  7.     # data is now $_[0]
  8.     my $size    = $_[1];
  9.     my $offset  = $_[2] || 0;
  10.     my $timeout = $_[3];
  11.  
  12.     my $rin = '';
  13.     vec($rin, fileno($fd), 1) = 1;
  14.     my $err;
  15.     my $nfound = select($rin, undef, $err = $rin, $timeout);
  16.     if ($nfound == 0) {
  17.     die "Timeout";
  18.     } elsif ($nfound < 0) {
  19.     die "Select failed: $!";
  20.     } elsif ($err =~ /[^\0]/) {
  21.     die "Exception while reading on socket handle";
  22.     } else {
  23.     my $n = sysread($fd, $_[0], $size, $offset);
  24.     # Since so much data might pass here we cheat about debugging
  25.     if ($LWP::Debug::current_level{'conns'}) {
  26.         LWP::Debug::debug("Read $n bytes");
  27.         LWP::Debug::conns($_[0]) if $n;
  28.     }
  29.     return $n;
  30.     }
  31. }
  32.  
  33. 1;
  34.