1 ## $Id: //depot/libnet/Net/FTP/I.pm#11 $
2 ## Package to read/write on BINARY data connections
7 use vars qw(@ISA $buf $VERSION);
10 require Net::FTP::dataconn;
12 @ISA = qw(Net::FTP::dataconn);
17 local *buf = \$_[0]; shift;
18 my $size = shift || croak 'read($buf,$size,[$timeout])';
19 my $timeout = @_ ? shift : $data->timeout;
21 $data->can_read($timeout) or
25 my $blksize = ${*$data}{'net_ftp_blksize'};
26 $blksize = $size if $size > $blksize;
28 while(($l = length(${*$data})) < $size) {
29 $n += ($b = sysread($data, ${*$data}, $blksize, $l));
33 $n = $size < ($l = length(${*$data})) ? $size : $l;
35 $buf = substr(${*$data},0,$n);
36 substr(${*$data},0,$n) = '';
38 ${*$data}{'net_ftp_bytesread'} += $n if $n;
39 ${*$data}{'net_ftp_eof'} = 1 unless $n;
46 local *buf = \$_[0]; shift;
47 my $size = shift || croak 'write($buf,$size,[$timeout])';
48 my $timeout = @_ ? shift : $data->timeout;
50 # If the remote server has closed the connection we will be signal'd
51 # when we write. This can happen if the disk on the remote server fills up
53 local $SIG{PIPE} = 'IGNORE' unless $^O eq 'MacOS';
57 my $blksize = ${*$data}{'net_ftp_blksize'};
59 $data->can_write($timeout) or
62 my $n = syswrite($data, $buf, $sent > $blksize ? $blksize : $sent ,$off);
63 return undef unless defined($n);