File tree Expand file tree Collapse file tree 1 file changed +13
-20
lines changed
crates/shadowsocks-service/src/local/dns Expand file tree Collapse file tree 1 file changed +13
-20
lines changed Original file line number Diff line number Diff line change 3
3
#[ cfg( unix) ]
4
4
use std:: path:: Path ;
5
5
use std:: {
6
+ cmp:: Ordering ,
6
7
io:: { self , ErrorKind } ,
7
8
net:: SocketAddr ,
8
9
sync:: Arc ,
@@ -170,20 +171,16 @@ impl DnsClient {
170
171
libc:: MSG_PEEK | libc:: MSG_DONTWAIT ,
171
172
) ;
172
173
173
- if ret == 0 {
174
+ match ret. cmp ( & 0 ) {
174
175
// EOF, connection lost
175
- false
176
- } else if ret > 0 {
176
+ Ordering :: Equal => false ,
177
177
// Data in buffer
178
- true
179
- } else {
180
- let err = io:: Error :: last_os_error ( ) ;
181
- if err. kind ( ) == ErrorKind :: WouldBlock {
178
+ Ordering :: Greater => true ,
179
+ Ordering :: Less => {
180
+ let err = io:: Error :: last_os_error ( ) ;
182
181
// EAGAIN, EWOULDBLOCK
183
182
// Still connected.
184
- true
185
- } else {
186
- false
183
+ err. kind ( ) == ErrorKind :: WouldBlock
187
184
}
188
185
}
189
186
}
@@ -208,20 +205,16 @@ impl DnsClient {
208
205
MSG_PEEK ,
209
206
) ;
210
207
211
- if ret == 0 {
208
+ match ret. cmp ( & 0 ) {
212
209
// EOF, connection lost
213
- false
214
- } else if ret > 0 {
210
+ Ordering :: Equal => false ,
215
211
// Data in buffer
216
- true
217
- } else {
218
- let err = io:: Error :: last_os_error ( ) ;
219
- if err. kind ( ) == ErrorKind :: WouldBlock {
212
+ Ordering :: Greater => true ,
213
+ Ordering :: Less => {
214
+ let err = io:: Error :: last_os_error ( ) ;
220
215
// I have to trust the `s` have already set to non-blocking mode
221
216
// Becuase windows doesn't have MSG_DONTWAIT
222
- true
223
- } else {
224
- false
217
+ err. kind ( ) == ErrorKind :: WouldBlock
225
218
}
226
219
}
227
220
}
You can’t perform that action at this time.
0 commit comments