@@ -20,6 +20,7 @@ use mercury::MercuryManager;
20
20
struct SessionData {
21
21
country : String ,
22
22
canonical_username : String ,
23
+ invalid : bool ,
23
24
}
24
25
25
26
struct SessionInternal {
@@ -77,7 +78,9 @@ impl Session {
77
78
reusable_credentials. username . clone ( ) ,
78
79
) ;
79
80
80
- handle. spawn ( task. map_err ( |e| panic ! ( e) ) ) ;
81
+ handle. spawn ( task. map_err ( |e| {
82
+ error ! ( "{:?}" , e) ;
83
+ } ) ) ;
81
84
82
85
session
83
86
} ) ;
@@ -104,6 +107,7 @@ impl Session {
104
107
data : RwLock :: new ( SessionData {
105
108
country : String :: new ( ) ,
106
109
canonical_username : username,
110
+ invalid : false ,
107
111
} ) ,
108
112
109
113
tx_connection : sender_tx,
@@ -212,6 +216,15 @@ impl Session {
212
216
pub fn session_id ( & self ) -> usize {
213
217
self . 0 . session_id
214
218
}
219
+
220
+ pub fn shutdown ( & self ) {
221
+ debug ! ( "Invalidating session[{}]" , self . 0 . session_id) ;
222
+ self . 0 . data . write ( ) . unwrap ( ) . invalid = true ;
223
+ }
224
+
225
+ pub fn is_invalid ( & self ) -> bool {
226
+ self . 0 . data . read ( ) . unwrap ( ) . invalid
227
+ }
215
228
}
216
229
217
230
#[ derive( Clone ) ]
@@ -240,6 +253,7 @@ where
240
253
impl < S > Future for DispatchTask < S >
241
254
where
242
255
S : Stream < Item = ( u8 , Bytes ) > ,
256
+ <S as Stream >:: Error : :: std:: fmt:: Debug ,
243
257
{
244
258
type Item = ( ) ;
245
259
type Error = S :: Error ;
@@ -251,7 +265,15 @@ where
251
265
} ;
252
266
253
267
loop {
254
- let ( cmd, data) = try_ready ! ( self . 0 . poll( ) ) . expect ( "connection closed" ) ;
268
+ let ( cmd, data) = match self . 0 . poll ( ) {
269
+ Ok ( Async :: Ready ( t) ) => t,
270
+ Ok ( Async :: NotReady ) => return Ok ( Async :: NotReady ) ,
271
+ Err ( e) => {
272
+ session. shutdown ( ) ;
273
+ return Err ( From :: from ( e) ) ;
274
+ }
275
+ } . expect ( "connection closed" ) ;
276
+
255
277
session. dispatch ( cmd, data) ;
256
278
}
257
279
}
0 commit comments