Should be working correctly :))

This commit is contained in:
amatgil 2022-10-03 18:22:03 +02:00
parent 93d5806e49
commit 15c4327c85

View file

@ -399,6 +399,7 @@ pub fn sender<F: Fn(f32)>(args: &Vec<String>, on_progress: F) {
sc.write_safe(&len.to_be_bytes())
.expect("unable to send file length");
println!("Length: {}", &len);
let mut time_elapsed = unix_millis();
loop {
let read = file.read(&mut buf).expect("file read error");
if read == 0 && !env::var("QFT_STREAM").is_ok() {
@ -412,8 +413,9 @@ pub fn sender<F: Fn(f32)>(args: &Vec<String>, on_progress: F) {
bytes_sent += read as u64;
if (bytes_sent % (br * 20) as u64) < (br as u64) {
print!("\r\x1b[KSent {} bytes; Speed: {} kb/s",
bytes_sent, (read / 1000) / last_update as usize );
bytes_sent, br as usize * 20 / (unix_millis() - time_elapsed) as usize );
stdout().flush().unwrap();
time_elapsed = unix_millis();
}
if unix_millis() - last_update > 100 {
on_progress((bytes_sent + begin) as f32 / len as f32);
@ -466,6 +468,7 @@ pub fn receiver<F: Fn(f32)>(args: &Vec<String>, on_progress: F) {
]);
file.set_len(len).expect("unable to set file length");
println!("Length: {}", &len);
let mut time_elapsed = unix_millis();
loop {
let (mbuf, amount) = sc.read_safe(buf).expect("read error");
let buf = &mbuf.leak()[..amount];
@ -479,9 +482,10 @@ pub fn receiver<F: Fn(f32)>(args: &Vec<String>, on_progress: F) {
file.flush().expect("file flush error");
bytes_received += amount as u64;
if (bytes_received % (br * 20) as u64) < (br as u64) {
print!("\r\x1b[KSent {} bytes; Speed: {} kb/s",
bytes_sent, (read / 1000) / last_update as usize );
print!("\r\x1b[KReceived {} bytes; Speed: {} kb/s",
bytes_received, br as usize * 20 / (unix_millis() - time_elapsed) as usize );
stdout().flush().unwrap();
time_elapsed = unix_millis();
}
if unix_millis() - last_update > 100 {
on_progress((bytes_received + begin) as f32 / len as f32);