@@ -4,7 +4,6 @@ use std::net::SocketAddr;
44use std:: sync:: Arc ;
55
66use async_trait:: async_trait;
7- use crossbeam:: queue:: SegQueue ;
87use log:: { debug, info, warn} ;
98
109use crate :: bytes:: { ByteBuffer , ByteBufferMut , DynamicByteBuffer } ;
@@ -23,7 +22,7 @@ use crate::settings::{Settings, keys};
2322use crate :: socket:: error:: ServerSocketError ;
2423use crate :: tailor:: { IdentityType , PacketFlags , ReturnCode , ServerConnectionHandler , Tailor } ;
2524use crate :: utils:: socket:: Socket ;
26- use crate :: utils:: sync:: { AsyncExecutor , Mutex , NotifyQueueReceiver , RwLock , WatchReceiver , WatchSender , create_bounded_notify_queue, create_notify_queue, create_watch } ;
25+ use crate :: utils:: sync:: { AsyncExecutor , Mutex , NotifyQueueReceiver , NotifyQueueSender , RwLock , create_bounded_notify_queue, create_notify_queue} ;
2726use crate :: utils:: unix_timestamp_ms;
2827
2928/// Configuration for a single server flow manager.
@@ -220,17 +219,16 @@ impl<T: IdentityType + Clone + Eq + Hash + Send + ToString + 'static, AE: AsyncE
220219 } ;
221220 info ! ( "listener built: max_data_payload={}B (mtu={}B, {} flow(s))" , max_data_payload, settings. mtu( ) , flows. len( ) ) ;
222221
223- let ( accept_signal_tx , accept_signal_rx ) = create_watch ( ) ;
222+ let ( accept_tx , accept_rx ) = create_notify_queue :: < ClientHandle < T , AE > > ( ) ;
224223
225224 Ok ( Listener {
226225 flows,
227226 sessions : RwLock :: new ( HashMap :: new ( ) ) ,
228227 users : Mutex :: new ( users) ,
229228 secret : self . secret ,
230229 identity_generator : self . identity_generator ,
231- accept_queue : SegQueue :: new ( ) ,
232- accept_signal_tx,
233- accept_signal_rx : Mutex :: new ( accept_signal_rx) ,
230+ accept_tx,
231+ accept_rx : Mutex :: new ( accept_rx) ,
234232 max_data_payload,
235233 settings,
236234 } )
@@ -291,17 +289,16 @@ impl<T: IdentityType + Clone + Eq + Hash + Send + ToString + 'static, AE: AsyncE
291289 } ;
292290 info ! ( "listener built: max_data_payload={}B (mtu={}B, {} flow(s))" , max_data_payload, settings. mtu( ) , flows. len( ) ) ;
293291
294- let ( accept_signal_tx , accept_signal_rx ) = create_watch ( ) ;
292+ let ( accept_tx , accept_rx ) = create_notify_queue :: < ClientHandle < T , AE > > ( ) ;
295293
296294 Ok ( Listener {
297295 flows,
298296 sessions : RwLock :: new ( HashMap :: new ( ) ) ,
299297 users : Mutex :: new ( users) ,
300298 secret : secret_arc,
301299 identity_generator : self . identity_generator ,
302- accept_queue : SegQueue :: new ( ) ,
303- accept_signal_tx,
304- accept_signal_rx : Mutex :: new ( accept_signal_rx) ,
300+ accept_tx,
301+ accept_rx : Mutex :: new ( accept_rx) ,
305302 max_data_payload,
306303 settings,
307304 } )
@@ -318,9 +315,8 @@ pub struct Listener<T: IdentityType + Clone + Eq + Hash + Send + ToString + 'sta
318315 #[ cfg( any( feature = "full_software" , feature = "full_hardware" ) ) ]
319316 secret : Arc < ServerSecret < ' static > > ,
320317 identity_generator : IG ,
321- accept_queue : SegQueue < ClientHandle < T , AE > > ,
322- accept_signal_tx : WatchSender < ( ) > ,
323- accept_signal_rx : Mutex < WatchReceiver < ( ) > > ,
318+ accept_tx : NotifyQueueSender < ClientHandle < T , AE > > ,
319+ accept_rx : Mutex < NotifyQueueReceiver < ClientHandle < T , AE > > > ,
324320 /// Maximum user-data bytes per packet so the wire packet fits within MTU.
325321 max_data_payload : usize ,
326322 settings : Arc < Settings < AE > > ,
@@ -530,23 +526,14 @@ impl<T: IdentityType + Clone + Eq + Hash + Send + ToString + 'static, AE: AsyncE
530526 max_data_payload : self . max_data_payload ,
531527 settings : self . settings . clone ( ) ,
532528 } ;
533- self . accept_queue . push ( client_handle) ;
534- self . accept_signal_tx . send ( ( ) ) ;
529+ self . accept_tx . push ( client_handle) ;
535530
536531 info ! ( "new client connected: {}" , identity. to_string( ) ) ;
537532 }
538533
539534 /// Wait for the next client connection and return a handle to it.
540535 pub async fn accept ( & self ) -> Result < ClientHandle < T , AE > , ServerSocketError > {
541- loop {
542- if let Some ( handle) = self . accept_queue . pop ( ) {
543- return Ok ( handle) ;
544- }
545- match self . accept_signal_rx . lock ( ) . await . recv ( ) . await {
546- Some ( ( ) ) => { }
547- None => return Err ( ServerSocketError :: ListenerStopped ) ,
548- }
549- }
536+ self . accept_rx . lock ( ) . await . recv ( ) . await . ok_or ( ServerSocketError :: ListenerStopped )
550537 }
551538}
552539
0 commit comments