File tree Expand file tree Collapse file tree 1 file changed +10
-11
lines changed Expand file tree Collapse file tree 1 file changed +10
-11
lines changed Original file line number Diff line number Diff line change @@ -37,9 +37,7 @@ pub fn start() {
37
37
38
38
let mut connections = connections. lock ( ) . unwrap ( ) ;
39
39
40
- let mut next_connections = vec ! [ ] ;
41
-
42
- while let Some ( mut stream) = connections. pop ( ) {
40
+ connections. retain_mut ( |stream| {
43
41
let mut buffer = [ 0 ; 1024 ] ;
44
42
45
43
let received = stream. read ( & mut buffer) ;
@@ -49,19 +47,20 @@ pub fn start() {
49
47
if num_bytes_read == 0 {
50
48
let addr = stream. peer_addr ( ) . unwrap ( ) ;
51
49
println ! ( "Connection closed by: {}" , addr) ;
52
- } else {
53
- parse_packets ( buffer, & mut stream) ;
54
- next_connections. push ( stream) ;
50
+ return false ;
55
51
}
52
+ parse_packets ( buffer, stream) ;
53
+ true
56
54
}
57
55
Err ( e) => match e. kind ( ) {
58
- WouldBlock => next_connections. push ( stream) ,
59
- _ => println ! ( "Unexpected error from stream.read(): {:?}" , e) ,
56
+ WouldBlock => true ,
57
+ _ => {
58
+ println ! ( "Unexpected error from stream.read(): {:?}" , e) ;
59
+ false
60
+ }
60
61
} ,
61
62
}
62
- }
63
-
64
- * connections = next_connections;
63
+ } ) ;
65
64
}
66
65
}
67
66
You can’t perform that action at this time.
0 commit comments