1N/A## $Id: //depot/libnet/Net/FTP/I.pm#13 $
1N/A## Package to read/write on BINARY data connections
1N/A##
1N/A
1N/Apackage Net::FTP::I;
1N/A
1N/Ause vars qw(@ISA $buf $VERSION);
1N/Ause Carp;
1N/A
1N/Arequire Net::FTP::dataconn;
1N/A
1N/A@ISA = qw(Net::FTP::dataconn);
1N/A$VERSION = "1.12";
1N/A
1N/Asub read {
1N/A my $data = shift;
1N/A local *buf = \$_[0]; shift;
1N/A my $size = shift || croak 'read($buf,$size,[$timeout])';
1N/A my $timeout = @_ ? shift : $data->timeout;
1N/A
1N/A my $n;
1N/A
1N/A if ($size > length ${*$data} and !${*$data}{'net_ftp_eof'}) {
1N/A $data->can_read($timeout) or
1N/A croak "Timeout";
1N/A
1N/A my $blksize = ${*$data}{'net_ftp_blksize'};
1N/A $blksize = $size if $size > $blksize;
1N/A
1N/A unless ($n = sysread($data, ${*$data}, $blksize, length ${*$data})) {
1N/A return undef unless defined $n;
1N/A ${*$data}{'net_ftp_eof'} = 1;
1N/A }
1N/A }
1N/A
1N/A $buf = substr(${*$data},0,$size);
1N/A
1N/A $n = length($buf);
1N/A
1N/A substr(${*$data},0,$n) = '';
1N/A
1N/A ${*$data}{'net_ftp_bytesread'} += $n;
1N/A
1N/A $n;
1N/A}
1N/A
1N/Asub write {
1N/A my $data = shift;
1N/A local *buf = \$_[0]; shift;
1N/A my $size = shift || croak 'write($buf,$size,[$timeout])';
1N/A my $timeout = @_ ? shift : $data->timeout;
1N/A
1N/A # If the remote server has closed the connection we will be signal'd
1N/A # when we write. This can happen if the disk on the remote server fills up
1N/A
1N/A local $SIG{PIPE} = 'IGNORE' unless $^O eq 'MacOS';
1N/A my $sent = $size;
1N/A my $off = 0;
1N/A
1N/A my $blksize = ${*$data}{'net_ftp_blksize'};
1N/A while($sent > 0) {
1N/A $data->can_write($timeout) or
1N/A croak "Timeout";
1N/A
1N/A my $n = syswrite($data, $buf, $sent > $blksize ? $blksize : $sent ,$off);
1N/A return undef unless defined($n);
1N/A $sent -= $n;
1N/A $off += $n;
1N/A }
1N/A
1N/A $size;
1N/A}
1N/A
1N/A1;