1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

ftp: fix an error (#7930)

This commit is contained in:
yuyi 2021-01-08 03:21:47 +08:00 committed by GitHub
parent 2ad2d68d7c
commit ad79d55a5c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 13 deletions

View File

@ -32,9 +32,6 @@ pub fn new_buffered_reader(o BufferedReaderConfig) &BufferedReader {
// read fufills the Reader interface
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
if r.needs_fill() {
if !r.fill_buffer() {
@ -53,7 +50,7 @@ fn (mut r BufferedReader) fill_buffer() bool {
if r.end_of_stream {
// we know we have already reached the end of stream
// so return early
return false
return true
}
r.offset = 0
r.len = 0
@ -117,4 +114,3 @@ pub fn (mut r BufferedReader) read_line() ?string {
r.offset = i
}
}

View File

@ -43,8 +43,15 @@ mut:
}
fn (mut dtp DTP) read() ?[]byte {
mut data := []byte{len: 1024}
dtp.reader.read(mut data) ?
mut data := []byte{}
mut buf := []byte{len: 1024}
for {
len := dtp.reader.read(mut buf) or { break }
if len == 0 {
break
}
data << buf[..len]
}
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) {
return error('Bad message')
}
ip, port := get_host_ip_from_dtp_message(msg)
conn := net.dial_tcp('$ip:$port') or { return error('Cannot connect to the data channel') }
dtp := DTP{
conn: conn
reader: io.new_buffered_reader(reader: io.make_reader(conn))
mut dtp := &DTP{
ip: ip
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
}
fn (mut ftp FTP) pasv() ?DTP {
fn (mut ftp FTP) pasv() ?&DTP {
ftp.write('PASV') ?
code, data := ftp.read() ?
$if debug {