File tree Expand file tree Collapse file tree 3 files changed +6
-22
lines changed Expand file tree Collapse file tree 3 files changed +6
-22
lines changed Original file line number Diff line number Diff line change @@ -2,8 +2,10 @@ use crate::{
2
2
connection:: { BaseConnection , Buffer } ,
3
3
utils:: { Error , READ_BUFFER_SIZE } ,
4
4
} ;
5
+ use std:: time:: Duration ;
5
6
6
7
use async_std:: {
8
+ io,
7
9
net:: { Shutdown , TcpStream } ,
8
10
prelude:: * ,
9
11
} ;
@@ -35,7 +37,8 @@ impl BaseConnection for InetSocketConnection {
35
37
if let Err ( err) = result {
36
38
return Err ( Error :: Internal ( format ! ( "{}" , err) ) ) ;
37
39
}
38
- self . client = Some ( result. unwrap ( ) ) ;
40
+ let client = result. unwrap ( ) ;
41
+ self . client = Some ( client) ;
39
42
40
43
self . connection_setup = true ;
41
44
Ok ( ( ) )
@@ -72,9 +75,9 @@ impl BaseConnection for InetSocketConnection {
72
75
let mut read_size = READ_BUFFER_SIZE ;
73
76
while read_size > 0 {
74
77
let mut buf = [ 0u8 ; READ_BUFFER_SIZE ] ;
75
- let result = client. read ( & mut buf) . await ;
78
+ let result = io :: timeout ( Duration :: from_millis ( 10 ) , client. read ( & mut buf) ) . await ;
76
79
if result. is_err ( ) {
77
- return None ;
80
+ return Some ( buffer ) ;
78
81
}
79
82
read_size = result. unwrap ( ) ;
80
83
buffer. extend ( buf[ ..read_size] . iter ( ) ) ;
Original file line number Diff line number Diff line change @@ -126,11 +126,4 @@ impl BaseProtocol {
126
126
_ => panic ! ( "Currently, only JsonProtocol is supported" ) ,
127
127
}
128
128
}
129
-
130
- pub fn decode ( & self , data : & [ u8 ] ) -> BaseMessage {
131
- match self {
132
- BaseProtocol :: JsonProtocol { .. } => json_protocol:: decode ( & self , data) ,
133
- _ => panic ! ( "Currently, only JsonProtocol is supported" ) ,
134
- }
135
- }
136
129
}
Original file line number Diff line number Diff line change @@ -164,18 +164,6 @@ pub fn get_next_message(protocol: &mut BaseProtocol) -> Option<BaseMessage> {
164
164
}
165
165
}
166
166
167
- pub fn decode ( protocol : & BaseProtocol , data : & [ u8 ] ) -> BaseMessage {
168
- match protocol {
169
- BaseProtocol :: JsonProtocol { .. } => match decode_internal ( data) {
170
- Some ( message) => message,
171
- None => BaseMessage :: Unknown {
172
- request_id : String :: default ( ) ,
173
- } ,
174
- } ,
175
- _ => panic ! ( "BaseProtocol tried to decode a non-JsonProtocol as a JsonProtocol" ) ,
176
- }
177
- }
178
-
179
167
fn decode_internal ( data : & [ u8 ] ) -> Option < BaseMessage > {
180
168
let result: Result < Value > = from_slice ( data) ;
181
169
if result. is_err ( ) {
You can’t perform that action at this time.
0 commit comments