Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
T
tcpserver
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
substrate
tcpserver
Commits
d9c43730
Commit
d9c43730
authored
Mar 23, 2021
by
邢兆忠
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
modify
parent
f16bdb28
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
3 additions
and
16 deletions
+3
-16
src/main.rs
+3
-16
No files found.
src/main.rs
View file @
d9c43730
...
...
@@ -4,10 +4,6 @@ use std::thread;
use
std
::
time
;
use
std
::
str
;
fn
read_byte
(
_url
:
&
String
)
->
Result
<
(),
&
'static
str
>
{
Err
(
"input error."
)
}
//循环
fn
handle_client
(
mut
stream
:
TcpStream
)
->
Result
<
(),
Error
>
{
let
mut
buf
=
[
0
;
512
];
...
...
@@ -17,17 +13,9 @@ fn handle_client(mut stream: TcpStream) -> Result<(), Error>{
//输入内容字节数
let
bytes_read
=
stream
.read
(
&
mut
buf
)
?
;
//字节数为0则结束
match
read_byte
(
bytes_read
)
{
Ok
(
k
)
=>
{
stream
.read
(
&
mut
buf
)
?
;
},
Err
(
e
)
=>
{
println!
(
"Failed to open the file."
);
}
};
// if bytes_read == 0 {
// return Ok(());
// }
if
bytes_read
==
0
{
return
Ok
(());
}
//字节数
println!
(
"format {} arguments"
,
bytes_read
);
//写回到stream中
...
...
@@ -56,7 +44,6 @@ fn main() -> std::io::Result<()> {
let
handle
=
thread
::
spawn
(
||
{
//调用handle_client,有错误抛出异常unwrap_or_else类似match
handle_client
(
stream
)
.unwrap_or_else
(|
error
|
eprintln!
(
"{:?}"
,
error
));
//Err(error);
});
eprintln!
(
"handle ==========={:?}"
,
handle
);
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment