allow resuming writes
This commit is contained in:
parent
300e558df2
commit
8aa7fe2129
3 changed files with 23 additions and 9 deletions
2
Cargo.lock
generated
2
Cargo.lock
generated
|
@ -4,4 +4,4 @@ version = 3
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "qft"
|
name = "qft"
|
||||||
version = "0.1.11"
|
version = "0.2.0"
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "qft"
|
name = "qft"
|
||||||
version = "0.1.11"
|
version = "0.2.0"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
28
src/main.rs
28
src/main.rs
|
@ -1,7 +1,7 @@
|
||||||
use std::{
|
use std::{
|
||||||
collections::HashMap,
|
collections::HashMap,
|
||||||
fs::File,
|
fs::{File, OpenOptions},
|
||||||
io::{stdout, Error, Read, Write},
|
io::{stdout, Error, Read, Write, Seek, SeekFrom},
|
||||||
net::*,
|
net::*,
|
||||||
str::FromStr,
|
str::FromStr,
|
||||||
thread,
|
thread,
|
||||||
|
@ -67,7 +67,7 @@ impl SafeReadWrite {
|
||||||
panic!("bad buf length")
|
panic!("bad buf length")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(x) => return Err(x),
|
Err(_) => {}
|
||||||
}
|
}
|
||||||
let mut buf = [0, 0];
|
let mut buf = [0, 0];
|
||||||
match self.socket.recv(&mut buf).ok() {
|
match self.socket.recv(&mut buf).ok() {
|
||||||
|
@ -147,7 +147,7 @@ impl SafeReadWrite {
|
||||||
panic!("internet down")
|
panic!("internet down")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(_) => return self.socket,
|
Err(_) => {},
|
||||||
}
|
}
|
||||||
let mut buf = [0, 0];
|
let mut buf = [0, 0];
|
||||||
match self.socket.recv(&mut buf).ok() {
|
match self.socket.recv(&mut buf).ok() {
|
||||||
|
@ -227,6 +227,7 @@ fn sender(args: &Vec<String>) {
|
||||||
let connection = holepunch(args);
|
let connection = holepunch(args);
|
||||||
let br = u32::from_str_radix(args.get(5).unwrap_or(&"256".to_string()), 10)
|
let br = u32::from_str_radix(args.get(5).unwrap_or(&"256".to_string()), 10)
|
||||||
.expect("This is not a correct number");
|
.expect("This is not a correct number");
|
||||||
|
let begin = args.get(6).map(|s| u64::from_str_radix(s.as_str(), 10)).unwrap_or(Ok(0)).expect("bad begin operand");
|
||||||
let mut buf: Vec<u8> = Vec::new();
|
let mut buf: Vec<u8> = Vec::new();
|
||||||
buf.resize(br as usize, 0);
|
buf.resize(br as usize, 0);
|
||||||
let mut buf = buf.leak();
|
let mut buf = buf.leak();
|
||||||
|
@ -236,6 +237,12 @@ fn sender(args: &Vec<String>) {
|
||||||
}))
|
}))
|
||||||
.expect("file not readable");
|
.expect("file not readable");
|
||||||
|
|
||||||
|
if begin != 0 {
|
||||||
|
println!("Skipping to {}...", begin);
|
||||||
|
file.seek(SeekFrom::Start(begin)).expect("unable to skip");
|
||||||
|
println!("Done.");
|
||||||
|
}
|
||||||
|
|
||||||
let mut sc = SafeReadWrite::new(connection);
|
let mut sc = SafeReadWrite::new(connection);
|
||||||
let mut bytes_sent: u64 = 0;
|
let mut bytes_sent: u64 = 0;
|
||||||
loop {
|
loop {
|
||||||
|
@ -261,15 +268,22 @@ fn receiver(args: &Vec<String>) {
|
||||||
let connection = holepunch(args);
|
let connection = holepunch(args);
|
||||||
let br = u32::from_str_radix(args.get(5).unwrap_or(&"256".to_string()), 10)
|
let br = u32::from_str_radix(args.get(5).unwrap_or(&"256".to_string()), 10)
|
||||||
.expect("This is not a correct number");
|
.expect("This is not a correct number");
|
||||||
|
let begin = args.get(6).map(|s| u64::from_str_radix(s.as_str(), 10)).unwrap_or(Ok(0)).expect("bad begin operand");
|
||||||
let mut buf: Vec<u8> = Vec::new();
|
let mut buf: Vec<u8> = Vec::new();
|
||||||
buf.resize(br as usize, 0);
|
buf.resize(br as usize, 0);
|
||||||
let mut buf: &[u8] = buf.leak();
|
let mut buf: &[u8] = buf.leak();
|
||||||
let mut file = File::create(args.get(4).unwrap_or_else(|| {
|
let mut file = OpenOptions::new().truncate(false).open(args.get(4).unwrap_or_else(|| {
|
||||||
print_args(args);
|
print_args(args);
|
||||||
panic!("unreachable")
|
panic!("unreachable")
|
||||||
}))
|
}))
|
||||||
.expect("file not writable");
|
.expect("file not writable");
|
||||||
|
|
||||||
|
if begin != 0 {
|
||||||
|
println!("Skipping to {}...", begin);
|
||||||
|
file.seek(SeekFrom::Start(begin)).expect("unable to skip");
|
||||||
|
println!("Done.");
|
||||||
|
}
|
||||||
|
|
||||||
let mut sc = SafeReadWrite::new(connection);
|
let mut sc = SafeReadWrite::new(connection);
|
||||||
let mut bytes_received: u64 = 0;
|
let mut bytes_received: u64 = 0;
|
||||||
loop {
|
loop {
|
||||||
|
@ -358,8 +372,8 @@ fn print_args(args: &Vec<String>) {
|
||||||
println!(
|
println!(
|
||||||
"No arguments. Needed: \n\
|
"No arguments. Needed: \n\
|
||||||
| {} helper <bind-port>\n\
|
| {} helper <bind-port>\n\
|
||||||
| {} sender <helper-address>:<helper-port> <phrase> <filename> [bitrate]\n\
|
| {} sender <helper-address>:<helper-port> <phrase> <filename> [bitrate] [skip]\n\
|
||||||
| {} receiver <helper-address>:<helper-port> <phrase> <filename> [bitrate]\n",
|
| {} receiver <helper-address>:<helper-port> <phrase> <filename> [bitrate] [skip]\n",
|
||||||
f, f, f
|
f, f, f
|
||||||
);
|
);
|
||||||
panic!("No arguments");
|
panic!("No arguments");
|
||||||
|
|
Loading…
Reference in a new issue