@@ -10,6 +10,7 @@ use std::{
1010} ;
1111
1212use crate :: runtime:: { AsyncTimer , AsyncUdpSocket , Runtime } ;
13+ use atomic_waker:: AtomicWaker ;
1314use bytes:: { Bytes , BytesMut } ;
1415use pin_project_lite:: pin_project;
1516use proto:: { ConnectionError , ConnectionHandle , ConnectionStats , Dir , StreamEvent , StreamId } ;
@@ -40,6 +41,7 @@ impl Connecting {
4041 handle : ConnectionHandle ,
4142 conn : proto:: Connection ,
4243 endpoint_events : mpsc:: UnboundedSender < ( ConnectionHandle , EndpointEvent ) > ,
44+ endpoint_driver : Arc < AtomicWaker > ,
4345 conn_events : mpsc:: UnboundedReceiver < ConnectionEvent > ,
4446 socket : Arc < dyn AsyncUdpSocket > ,
4547 runtime : Arc < dyn Runtime > ,
@@ -50,6 +52,7 @@ impl Connecting {
5052 handle,
5153 conn,
5254 endpoint_events,
55+ endpoint_driver,
5356 conn_events,
5457 on_handshake_data_send,
5558 on_connected_send,
@@ -233,7 +236,7 @@ impl Future for ConnectionDriver {
233236 // If a timer expires, there might be more to transmit. When we transmit something, we
234237 // might need to reset a timer. Hence, we must loop until neither happens.
235238 keep_going |= conn. drive_timer ( cx) ;
236- conn. forward_endpoint_events ( ) ;
239+ conn. forward_endpoint_events ( & self . 0 . shared ) ;
237240 conn. forward_app_events ( & self . 0 . shared ) ;
238241
239242 if !conn. inner . is_drained ( ) {
@@ -759,6 +762,7 @@ impl ConnectionRef {
759762 handle : ConnectionHandle ,
760763 conn : proto:: Connection ,
761764 endpoint_events : mpsc:: UnboundedSender < ( ConnectionHandle , EndpointEvent ) > ,
765+ endpoint_driver : Arc < AtomicWaker > ,
762766 conn_events : mpsc:: UnboundedReceiver < ConnectionEvent > ,
763767 on_handshake_data : oneshot:: Sender < ( ) > ,
764768 on_connected : oneshot:: Sender < bool > ,
@@ -786,7 +790,13 @@ impl ConnectionRef {
786790 socket,
787791 runtime,
788792 } ) ,
789- shared : Shared :: default ( ) ,
793+ shared : Shared {
794+ endpoint_driver,
795+ stream_budget_available : Default :: default ( ) ,
796+ stream_incoming : Default :: default ( ) ,
797+ datagrams : Default :: default ( ) ,
798+ closed : Default :: default ( ) ,
799+ } ,
790800 } ) )
791801 }
792802
@@ -831,7 +841,7 @@ pub(crate) struct ConnectionInner {
831841 pub ( crate ) shared : Shared ,
832842}
833843
834- #[ derive( Debug , Default ) ]
844+ #[ derive( Debug ) ]
835845pub ( crate ) struct Shared {
836846 /// Notified when new streams may be locally initiated due to an increase in stream ID flow
837847 /// control budget
@@ -840,6 +850,7 @@ pub(crate) struct Shared {
840850 stream_incoming : [ Notify ; 2 ] ,
841851 datagrams : Notify ,
842852 closed : Notify ,
853+ endpoint_driver : Arc < AtomicWaker > ,
843854}
844855
845856pub ( crate ) struct State {
@@ -898,18 +909,17 @@ impl State {
898909 false
899910 }
900911
901- fn forward_endpoint_events ( & mut self ) {
912+ fn forward_endpoint_events ( & mut self , shared : & Shared ) {
902913 if !self . inner . poll_endpoint_events ( ) {
903914 return ;
904915 }
905- // If the endpoint driver is gone, noop.
906- let _ = self . endpoint_events . send ( (
907- self . handle ,
908- match self . inner . is_drained ( ) {
909- false => EndpointEvent :: Proto ,
910- true => EndpointEvent :: Drained ,
911- } ,
912- ) ) ;
916+ shared. endpoint_driver . wake ( ) ;
917+ if self . inner . is_drained ( ) {
918+ // If the endpoint driver is gone, noop.
919+ let _ = self
920+ . endpoint_events
921+ . send ( ( self . handle , EndpointEvent :: Drained ) ) ;
922+ }
913923 }
914924
915925 /// If this returns `Err`, the endpoint is dead, so the driver should exit immediately.
0 commit comments