2 ## Generic data connection package
5 package Net::FTP::dataconn;
8 use vars qw(@ISA $timeout $VERSION);
13 @ISA = qw(IO::Socket::INET);
18 ${*$data}{'net_ftp_bytesread'} = 0;
24 my $ftp = ${*$data}{'net_ftp_cmd'};
26 # no need to abort if we have finished the xfer
28 if ${*$data}{'net_ftp_eof'};
30 # for some reason if we continously open RETR connections and not
31 # read a single byte, then abort them after a while the server will
32 # close our connection, this prevents the unexpected EOF on the
33 # command channel -- GMB
34 if (exists ${*$data}{'net_ftp_bytesread'}
35 && (${*$data}{'net_ftp_bytesread'} == 0))
38 my $timeout = $data->timeout;
39 $data->can_read($timeout) && sysread($data, $buf, 1);
42 ${*$data}{'net_ftp_eof'} = 1; # fake
44 $ftp->abort; # this will close me
50 my $ftp = ${*$data}{'net_ftp_cmd'};
52 $data->SUPER::close();
54 delete ${*$ftp}{'net_ftp_dataconn'}
55 if exists ${*$ftp}{'net_ftp_dataconn'}
56 && $data == ${*$ftp}{'net_ftp_dataconn'};
62 my $ftp = ${*$data}{'net_ftp_cmd'};
64 if (exists ${*$data}{'net_ftp_bytesread'} && !${*$data}{'net_ftp_eof'}) {
66 $data->read($junk, 1, 0);
67 return $data->abort unless ${*$data}{'net_ftp_eof'};
72 $ftp->response() == CMD_OK
73 && $ftp->message =~ /unique file name:\s*(\S*)\s*\)/
74 && (${*$ftp}{'net_ftp_unique'} = $1);
76 $ftp->status == CMD_OK;
81 my ($data, $timeout, $do_read) = @_;
82 my ($rin, $rout, $win, $wout, $tout, $nfound);
84 vec($rin = '', fileno($data), 1) = 1;
86 ($win, $rin) = ($rin, $win) unless $do_read;
89 $nfound = select($rout = $rin, $wout = $win, undef, $tout = $timeout);
102 _select(@_[0, 1], 1);
107 _select(@_[0, 1], 0);
114 ${*$ftp}{'net_ftp_cmd'};
121 ${*$ftp}{'net_ftp_bytesread'} || 0;