ftp: fix an error (#7930)
parent
2ad2d68d7c
commit
ad79d55a5c
|
@ -32,9 +32,6 @@ pub fn new_buffered_reader(o BufferedReaderConfig) &BufferedReader {
|
||||||
|
|
||||||
// read fufills the Reader interface
|
// read fufills the Reader interface
|
||||||
pub fn (mut r BufferedReader) read(mut buf []byte) ?int {
|
pub fn (mut r BufferedReader) read(mut buf []byte) ?int {
|
||||||
if r.end_of_stream {
|
|
||||||
return none
|
|
||||||
}
|
|
||||||
// read data out of the buffer if we dont have any
|
// read data out of the buffer if we dont have any
|
||||||
if r.needs_fill() {
|
if r.needs_fill() {
|
||||||
if !r.fill_buffer() {
|
if !r.fill_buffer() {
|
||||||
|
@ -53,7 +50,7 @@ fn (mut r BufferedReader) fill_buffer() bool {
|
||||||
if r.end_of_stream {
|
if r.end_of_stream {
|
||||||
// we know we have already reached the end of stream
|
// we know we have already reached the end of stream
|
||||||
// so return early
|
// so return early
|
||||||
return false
|
return true
|
||||||
}
|
}
|
||||||
r.offset = 0
|
r.offset = 0
|
||||||
r.len = 0
|
r.len = 0
|
||||||
|
@ -117,4 +114,3 @@ pub fn (mut r BufferedReader) read_line() ?string {
|
||||||
r.offset = i
|
r.offset = i
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -43,8 +43,15 @@ mut:
|
||||||
}
|
}
|
||||||
|
|
||||||
fn (mut dtp DTP) read() ?[]byte {
|
fn (mut dtp DTP) read() ?[]byte {
|
||||||
mut data := []byte{len: 1024}
|
mut data := []byte{}
|
||||||
dtp.reader.read(mut data) ?
|
mut buf := []byte{len: 1024}
|
||||||
|
for {
|
||||||
|
len := dtp.reader.read(mut buf) or { break }
|
||||||
|
if len == 0 {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
data << buf[..len]
|
||||||
|
}
|
||||||
return data
|
return data
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -163,22 +170,22 @@ pub fn (mut ftp FTP) cd(dir string) ? {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn new_dtp(msg string) ?DTP {
|
fn new_dtp(msg string) ?&DTP {
|
||||||
if !is_dtp_message_valid(msg) {
|
if !is_dtp_message_valid(msg) {
|
||||||
return error('Bad message')
|
return error('Bad message')
|
||||||
}
|
}
|
||||||
ip, port := get_host_ip_from_dtp_message(msg)
|
ip, port := get_host_ip_from_dtp_message(msg)
|
||||||
conn := net.dial_tcp('$ip:$port') or { return error('Cannot connect to the data channel') }
|
mut dtp := &DTP{
|
||||||
dtp := DTP{
|
|
||||||
conn: conn
|
|
||||||
reader: io.new_buffered_reader(reader: io.make_reader(conn))
|
|
||||||
ip: ip
|
ip: ip
|
||||||
port: port
|
port: port
|
||||||
}
|
}
|
||||||
|
conn := net.dial_tcp('$ip:$port') or { return error('Cannot connect to the data channel') }
|
||||||
|
dtp.conn = conn
|
||||||
|
dtp.reader = io.new_buffered_reader(reader: io.make_reader(dtp.conn))
|
||||||
return dtp
|
return dtp
|
||||||
}
|
}
|
||||||
|
|
||||||
fn (mut ftp FTP) pasv() ?DTP {
|
fn (mut ftp FTP) pasv() ?&DTP {
|
||||||
ftp.write('PASV') ?
|
ftp.write('PASV') ?
|
||||||
code, data := ftp.read() ?
|
code, data := ftp.read() ?
|
||||||
$if debug {
|
$if debug {
|
||||||
|
|
Loading…
Reference in New Issue