@@ -13,7 +13,10 @@ use crate::{
1313use std:: {
1414 collections:: { HashMap , HashSet , VecDeque } ,
1515 fmt,
16- sync:: { Arc , Mutex , Weak } ,
16+ sync:: {
17+ atomic:: { AtomicBool , Ordering } ,
18+ Arc , Mutex , Weak ,
19+ } ,
1720} ;
1821
1922pub use crate :: event:: DeviceCapability ;
@@ -49,6 +52,7 @@ struct ConnectionInner {
4952 devices : Mutex < HashMap < eis:: Device , Device > > ,
5053 device_for_interface : Mutex < HashMap < Object , Device > > ,
5154 last_serial : Mutex < u32 > ,
55+ disconnected : AtomicBool ,
5256}
5357
5458/// High-level server-side wrapper for `ei_connection`.
@@ -89,6 +93,18 @@ impl Connection {
8993 }
9094 self . connection ( )
9195 . disconnected ( self . last_serial ( ) , reason, explanation) ;
96+ // If flush fails because buffer is full, client can just get an EOF without
97+ // a message.
98+ let _ = self . flush ( ) ;
99+ self . 0 . disconnected . store ( true , Ordering :: SeqCst ) ;
100+ // Shutdown read end of socket, so anything reading/polling it will get EOF,
101+ // without waiting for client to disconnect first.
102+ self . 0 . context . 0 . shutdown_read ( ) ;
103+ }
104+
105+ #[ cfg( feature = "calloop" ) ]
106+ pub ( crate ) fn has_sent_disconnected ( & self ) -> bool {
107+ self . 0 . disconnected . load ( Ordering :: SeqCst )
92108 }
93109
94110 /// Sends buffered messages. Call after you're finished with sending events.
@@ -247,6 +263,7 @@ impl EisRequestConverter {
247263 devices : Mutex :: default ( ) ,
248264 device_for_interface : Mutex :: default ( ) ,
249265 last_serial : Mutex :: new ( initial_serial) ,
266+ disconnected : AtomicBool :: new ( false ) ,
250267 } ) ) ,
251268 }
252269 }
0 commit comments