9696 config_rx : mpsc:: UnboundedReceiver < BwCellConfig < P , Q > > ,
9797 timer : Timer ,
9898 state : AtomicI32 ,
99+ notify_rx : Option < tokio:: sync:: broadcast:: Receiver < crate :: control:: RattanNotify > > ,
100+ started : bool ,
99101}
100102
101103impl < P , Q > BwCellEgress < P , Q >
@@ -145,6 +147,25 @@ where
145147 Q : PacketQueue < P > ,
146148{
147149 async fn dequeue ( & mut self ) -> Option < P > {
150+ // Wait for Start notify if not started yet
151+ if !self . started {
152+ if let Some ( notify_rx) = & mut self . notify_rx {
153+ match notify_rx. recv ( ) . await {
154+ Ok ( crate :: control:: RattanNotify :: Start ) => {
155+ self . change_state ( 2 ) ;
156+ self . started = true ;
157+ }
158+ Ok ( crate :: control:: RattanNotify :: FirstPacket ) => {
159+ // Continue waiting for Start notify
160+ }
161+ Err ( _) => {
162+ // Notify channel closed, exit
163+ return None ;
164+ }
165+ }
166+ }
167+ }
168+
148169 // wait until next_available
149170 loop {
150171 tokio:: select! {
@@ -229,6 +250,13 @@ where
229250 self . state
230251 . store ( state, std:: sync:: atomic:: Ordering :: Release ) ;
231252 }
253+
254+ fn set_notify_receiver (
255+ & mut self ,
256+ notify_rx : tokio:: sync:: broadcast:: Receiver < crate :: control:: RattanNotify > ,
257+ ) {
258+ self . notify_rx = Some ( notify_rx) ;
259+ }
232260}
233261
234262#[ cfg_attr(
@@ -380,6 +408,8 @@ where
380408 config_rx,
381409 timer : Timer :: new ( ) ?,
382410 state : AtomicI32 :: new ( 0 ) ,
411+ notify_rx : None ,
412+ started : false ,
383413 } ,
384414 control_interface : Arc :: new ( BwCellControlInterface { config_tx } ) ,
385415 } )
@@ -404,6 +434,8 @@ where
404434 send_timer : Timer ,
405435 change_timer : Timer ,
406436 state : AtomicI32 ,
437+ notify_rx : Option < tokio:: sync:: broadcast:: Receiver < crate :: control:: RattanNotify > > ,
438+ started : bool ,
407439}
408440
409441impl < P , Q > BwReplayCellEgress < P , Q >
@@ -485,6 +517,26 @@ where
485517 Q : PacketQueue < P > ,
486518{
487519 async fn dequeue ( & mut self ) -> Option < P > {
520+ // Wait for Start notify if not started yet
521+ if !self . started {
522+ if let Some ( notify_rx) = & mut self . notify_rx {
523+ match notify_rx. recv ( ) . await {
524+ Ok ( crate :: control:: RattanNotify :: Start ) => {
525+ self . reset ( ) ;
526+ self . change_state ( 2 ) ;
527+ self . started = true ;
528+ }
529+ Ok ( crate :: control:: RattanNotify :: FirstPacket ) => {
530+ // Continue waiting for Start notify
531+ }
532+ Err ( _) => {
533+ // Notify channel closed, exit
534+ return None ;
535+ }
536+ }
537+ }
538+ }
539+
488540 // wait until next_available
489541 loop {
490542 tokio:: select! {
@@ -589,6 +641,13 @@ where
589641 self . state
590642 . store ( state, std:: sync:: atomic:: Ordering :: Release ) ;
591643 }
644+
645+ fn set_notify_receiver (
646+ & mut self ,
647+ notify_rx : tokio:: sync:: broadcast:: Receiver < crate :: control:: RattanNotify > ,
648+ ) {
649+ self . notify_rx = Some ( notify_rx) ;
650+ }
592651}
593652
594653#[ cfg_attr(
@@ -748,6 +807,8 @@ where
748807 send_timer : Timer :: new ( ) ?,
749808 change_timer : Timer :: new ( ) ?,
750809 state : AtomicI32 :: new ( 0 ) ,
810+ notify_rx : None ,
811+ started : false ,
751812 } ,
752813 control_interface : Arc :: new ( BwReplayCellControlInterface { config_tx } ) ,
753814 } )
0 commit comments