Merge pull request #3 from Tahinli/dev
feat: chunk size debug: prints open refactor: chunk type
This commit is contained in:
commit
94ee575402
1 changed files with 15 additions and 12 deletions
27
src/main.rs
27
src/main.rs
|
@ -5,7 +5,7 @@ use std::io::{Read, Write, self, BufWriter, BufReader, BufRead};
|
||||||
use std::env::{self};
|
use std::env::{self};
|
||||||
|
|
||||||
|
|
||||||
const BUFFER_SIZE:usize = 100000;
|
const BUFFER_SIZE:u64 = 1000000;
|
||||||
struct FileInfo
|
struct FileInfo
|
||||||
{
|
{
|
||||||
file:Option<File>,
|
file:Option<File>,
|
||||||
|
@ -73,21 +73,21 @@ impl FileInfo
|
||||||
fn send_file(&mut self, stream:&mut TcpStream)
|
fn send_file(&mut self, stream:&mut TcpStream)
|
||||||
{
|
{
|
||||||
let size = self.metadata.as_ref().unwrap().len();
|
let size = self.metadata.as_ref().unwrap().len();
|
||||||
let mut iteration = (size/BUFFER_SIZE as u64)+1;
|
let mut iteration = (size/BUFFER_SIZE)+1;
|
||||||
self.handshake_validation(stream, size);
|
self.handshake_validation(stream, size);
|
||||||
println!("Size = {}", size);
|
println!("Size = {}", size);
|
||||||
println!("Iteration = {}", iteration);
|
println!("Iteration = {}", iteration);
|
||||||
while iteration != 0
|
while iteration != 0
|
||||||
{
|
{
|
||||||
iteration -= 1;
|
iteration -= 1;
|
||||||
let mut buffer = [0u8;BUFFER_SIZE];
|
let mut buffer = [0u8;BUFFER_SIZE as usize];
|
||||||
if iteration != 0
|
if iteration != 0
|
||||||
{
|
{
|
||||||
self.read_exact(&mut buffer);
|
self.read_exact(&mut buffer);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
self.read_exact(&mut buffer[..(size%BUFFER_SIZE as u64) as usize]);
|
self.read_exact(&mut buffer[..(size%BUFFER_SIZE) as usize]);
|
||||||
}
|
}
|
||||||
self.send_exact(&mut buffer, stream);
|
self.send_exact(&mut buffer, stream);
|
||||||
|
|
||||||
|
@ -103,6 +103,7 @@ impl FileInfo
|
||||||
if handshake_callback == size.to_string().as_bytes().to_vec()
|
if handshake_callback == size.to_string().as_bytes().to_vec()
|
||||||
{
|
{
|
||||||
println!("Done: Handshake -> {}", self.location);
|
println!("Done: Handshake -> {}", self.location);
|
||||||
|
println!("{:#?} ", handshake_callback);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -140,7 +141,8 @@ impl FileInfo
|
||||||
Ok(_) =>
|
Ok(_) =>
|
||||||
{
|
{
|
||||||
self.size_current += buffer.len();
|
self.size_current += buffer.len();
|
||||||
//println!("Done: Send Bytes -> {}", self.location);
|
println!("Done: Send Bytes -> {}", self.location);
|
||||||
|
println!("{:#?}", buffer);
|
||||||
}
|
}
|
||||||
Err(err_val) =>
|
Err(err_val) =>
|
||||||
{
|
{
|
||||||
|
@ -169,7 +171,8 @@ impl FileInfo
|
||||||
Ok(_) =>
|
Ok(_) =>
|
||||||
{
|
{
|
||||||
self.size_current += buffer.len();
|
self.size_current += buffer.len();
|
||||||
//println!("Done: Receive Bytes -> {}", self.location);
|
println!("Done: Receive Bytes -> {}", self.location);
|
||||||
|
println!("{:#?}", buffer);
|
||||||
}
|
}
|
||||||
Err(err_val) =>
|
Err(err_val) =>
|
||||||
{
|
{
|
||||||
|
@ -186,7 +189,8 @@ impl FileInfo
|
||||||
{
|
{
|
||||||
Ok(_) =>
|
Ok(_) =>
|
||||||
{
|
{
|
||||||
//println!("Done: Receive Until -> {}", self.location);
|
println!("Done: Receive Until -> {}", self.location);
|
||||||
|
println!("{:#?}", buffer);
|
||||||
buffer.pop();
|
buffer.pop();
|
||||||
}
|
}
|
||||||
Err(err_val) =>
|
Err(err_val) =>
|
||||||
|
@ -207,7 +211,6 @@ impl FileInfo
|
||||||
{
|
{
|
||||||
Some(mut handshake) =>
|
Some(mut handshake) =>
|
||||||
{
|
{
|
||||||
// try then commit
|
|
||||||
println!("Done: Handshake -> {}", self.location);
|
println!("Done: Handshake -> {}", self.location);
|
||||||
println!("{:#?} ", handshake);
|
println!("{:#?} ", handshake);
|
||||||
let size = String::from_utf8(handshake.clone()).unwrap().parse().unwrap();
|
let size = String::from_utf8(handshake.clone()).unwrap().parse().unwrap();
|
||||||
|
@ -229,7 +232,7 @@ impl FileInfo
|
||||||
{
|
{
|
||||||
Ok(_) =>
|
Ok(_) =>
|
||||||
{
|
{
|
||||||
//println!("Done: Write -> {} | {} bytes", self.location, self.size_current);
|
println!("Done: Write -> {} | {} bytes", self.location, self.size_current);
|
||||||
}
|
}
|
||||||
Err(err_val) =>
|
Err(err_val) =>
|
||||||
{
|
{
|
||||||
|
@ -253,13 +256,13 @@ impl FileInfo
|
||||||
fn write_file(&mut self, stream:&mut TcpStream)
|
fn write_file(&mut self, stream:&mut TcpStream)
|
||||||
{
|
{
|
||||||
let size = self.handshake_recv(stream);
|
let size = self.handshake_recv(stream);
|
||||||
let mut iteration:u64 = (size/BUFFER_SIZE as u64)+1;
|
let mut iteration:u64 = (size/BUFFER_SIZE)+1;
|
||||||
println!("Size = {}", size);
|
println!("Size = {}", size);
|
||||||
println!("Iteration = {}", iteration);
|
println!("Iteration = {}", iteration);
|
||||||
while iteration != 0
|
while iteration != 0
|
||||||
{
|
{
|
||||||
iteration -= 1;
|
iteration -= 1;
|
||||||
let mut buffer = [0u8;BUFFER_SIZE];
|
let mut buffer = [0u8;BUFFER_SIZE as usize];
|
||||||
self.recv_exact(&mut buffer, stream);
|
self.recv_exact(&mut buffer, stream);
|
||||||
if iteration != 0
|
if iteration != 0
|
||||||
{
|
{
|
||||||
|
@ -267,7 +270,7 @@ impl FileInfo
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
self.save_exact(&buffer[..(size%BUFFER_SIZE as u64) as usize]);
|
self.save_exact(&buffer[..(size%BUFFER_SIZE) as usize]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue