Commit d9c43730 by 邢兆忠

modify

parent f16bdb28
...@@ -4,10 +4,6 @@ use std::thread; ...@@ -4,10 +4,6 @@ use std::thread;
use std::time; use std::time;
use std::str; use std::str;
fn read_byte(_url: &String) -> Result<(), &'static str>{
Err("input error.")
}
//循环 //循环
fn handle_client(mut stream: TcpStream) -> Result<(), Error>{ fn handle_client(mut stream: TcpStream) -> Result<(), Error>{
let mut buf = [0; 512]; let mut buf = [0; 512];
...@@ -17,17 +13,9 @@ fn handle_client(mut stream: TcpStream) -> Result<(), Error>{ ...@@ -17,17 +13,9 @@ fn handle_client(mut stream: TcpStream) -> Result<(), Error>{
//输入内容字节数 //输入内容字节数
let bytes_read = stream.read(&mut buf)?; let bytes_read = stream.read(&mut buf)?;
//字节数为0则结束 //字节数为0则结束
match read_byte(bytes_read) { if bytes_read == 0 {
Ok(k) => { return Ok(());
stream.read(&mut buf)?; }
},
Err(e) => {
println!("Failed to open the file.");
}
};
// if bytes_read == 0 {
// return Ok(());
// }
//字节数 //字节数
println!("format {} arguments", bytes_read); println!("format {} arguments", bytes_read);
//写回到stream中 //写回到stream中
...@@ -56,7 +44,6 @@ fn main() -> std::io::Result<()> { ...@@ -56,7 +44,6 @@ fn main() -> std::io::Result<()> {
let handle = thread::spawn( || { let handle = thread::spawn( || {
//调用handle_client,有错误抛出异常unwrap_or_else类似match //调用handle_client,有错误抛出异常unwrap_or_else类似match
handle_client(stream).unwrap_or_else(|error| eprintln!("{:?}", error)); handle_client(stream).unwrap_or_else(|error| eprintln!("{:?}", error));
//Err(error);
}); });
eprintln!("handle ==========={:?}", handle); eprintln!("handle ==========={:?}", handle);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment