2 ## Package to read/write on ASCII data connections
7 use vars qw(@ISA $buf $VERSION);
10 require Net::FTP::dataconn;
12 @ISA = qw(Net::FTP::dataconn);
13 $VERSION = "1.13"; # $Id: //depot/libnet/Net/FTP/A.pm#9 $
17 local *buf = \$_[0]; shift;
18 my $size = shift || croak 'read($buf,$size,[$offset])';
19 my $timeout = @_ ? shift : $data->timeout;
21 if (length(${*$data}) < $size && !${*$data}{'net_ftp_eof'}) {
22 my $blksize = ${*$data}{'net_ftp_blksize'};
23 $blksize = $size if $size > $blksize;
30 my $readbuf = defined(${*$data}{'net_ftp_cr'}) ? "\015" : '';
32 $data->can_read($timeout) or
35 if ($n = sysread($data, $readbuf, $blksize, length $readbuf)) {
36 ${*$data}{'net_ftp_bytesread'} += $n;
37 ${*$data}{'net_ftp_cr'} = substr($readbuf,-1) eq "\015"
45 ${*$data}{'net_ftp_eof'} = 1;
48 $readbuf =~ s/\015\012/\n/sgo;
49 ${*$data} .= $readbuf;
51 unless (length(${*$data})) {
56 $size = length(${*$data})
62 $buf = substr(${*$data},0,$size);
63 substr(${*$data},0,$size) = '';
70 local *buf = \$_[0]; shift;
71 my $size = shift || croak 'write($buf,$size,[$timeout])';
72 my $timeout = @_ ? shift : $data->timeout;
74 $data->can_write($timeout) or
77 (my $tmp = substr($buf,0,$size)) =~ s/\n/\015\012/sg;
79 # If the remote server has closed the connection we will be signal'd
80 # when we write. This can happen if the disk on the remote server fills up
82 local $SIG{PIPE} = 'IGNORE';
84 my $len = length($tmp);
90 $wrote = syswrite($data, substr($tmp,$off), $len);
92 unless defined($wrote);