@@ -8,11 +8,12 @@ use std::{
8
8
pin:: Pin ,
9
9
str,
10
10
sync:: { Arc , Mutex } ,
11
- task:: { Context , Poll , Waker } ,
11
+ task:: { Context , Poll } ,
12
12
time:: Instant ,
13
13
} ;
14
14
15
15
use crate :: runtime:: { default_runtime, AsyncUdpSocket , Runtime } ;
16
+ use atomic_waker:: AtomicWaker ;
16
17
use bytes:: { Bytes , BytesMut } ;
17
18
use pin_project_lite:: pin_project;
18
19
use proto:: {
@@ -319,10 +320,8 @@ impl Future for EndpointDriver {
319
320
320
321
#[ allow( unused_mut) ] // MSRV
321
322
fn poll ( mut self : Pin < & mut Self > , cx : & mut Context ) -> Poll < Self :: Output > {
323
+ self . 0 . shared . driver . register ( cx. waker ( ) ) ;
322
324
let mut endpoint = self . 0 . state . lock ( ) . unwrap ( ) ;
323
- if endpoint. driver . is_none ( ) {
324
- endpoint. driver = Some ( cx. waker ( ) . clone ( ) ) ;
325
- }
326
325
327
326
let now = Instant :: now ( ) ;
328
327
let mut keep_going = false ;
@@ -372,7 +371,6 @@ pub(crate) struct State {
372
371
inner : proto:: Endpoint ,
373
372
outgoing : VecDeque < udp:: Transmit > ,
374
373
incoming : VecDeque < Connecting > ,
375
- driver : Option < Waker > ,
376
374
ipv6 : bool ,
377
375
connections : ConnectionSet ,
378
376
events : mpsc:: UnboundedReceiver < ( ConnectionHandle , EndpointEvent ) > ,
@@ -391,6 +389,7 @@ pub(crate) struct State {
391
389
pub ( crate ) struct Shared {
392
390
incoming : Notify ,
393
391
idle : Notify ,
392
+ driver : Arc < AtomicWaker > ,
394
393
}
395
394
396
395
impl State {
@@ -705,7 +704,6 @@ impl EndpointRef {
705
704
events,
706
705
outgoing : VecDeque :: new ( ) ,
707
706
incoming : VecDeque :: new ( ) ,
708
- driver : None ,
709
707
connections : ConnectionSet {
710
708
senders : FxHashMap :: default ( ) ,
711
709
sender,
@@ -738,9 +736,7 @@ impl Drop for EndpointRef {
738
736
if x == 0 {
739
737
// If the driver is about to be on its own, ensure it can shut down if the last
740
738
// connection is gone.
741
- if let Some ( task) = endpoint. driver . take ( ) {
742
- task. wake ( ) ;
743
- }
739
+ self . 0 . shared . driver . wake ( ) ;
744
740
}
745
741
}
746
742
}
0 commit comments