@@ -10,17 +10,14 @@ use std::{
1010 net:: SocketAddr ,
1111 path:: PathBuf ,
1212 pin:: Pin ,
13- sync:: Arc ,
13+ sync:: { Arc , RwLock } ,
1414 task:: { Context , Poll } ,
1515 time:: { Duration , Instant } ,
1616} ;
1717
1818use async_trait:: async_trait;
1919use futures:: { Future , FutureExt } ;
20- use tokio:: {
21- io:: { AsyncRead , AsyncWrite } ,
22- sync:: watch,
23- } ;
20+ use tokio:: io:: { AsyncRead , AsyncWrite } ;
2421
2522pub mod ipc;
2623#[ cfg( feature = "quic" ) ]
4744 /// The inner IO object.
4845 inner : Io ,
4946 /// The sender for the stats.
50- sender : watch :: Sender < Arc < S > > ,
47+ stats : Arc < RwLock < Arc < S > > > ,
5148 /// The next time the stats should be refreshed.
5249 next_refresh : Instant ,
5350 /// The interval at which the stats should be refreshed.
@@ -130,10 +127,10 @@ where
130127 /// stats. The `sender` is used to send the latest stats to the caller.
131128 ///
132129 /// TODO: Specify configuration options.
133- pub fn new ( inner : Io , sender : watch :: Sender < Arc < S > > ) -> Self {
130+ pub fn new ( inner : Io , stats : Arc < RwLock < Arc < S > > > ) -> Self {
134131 Self {
135132 inner,
136- sender ,
133+ stats ,
137134 _marker : PhantomData ,
138135 next_refresh : Instant :: now ( ) ,
139136 refresh_interval : Duration :: from_secs ( 2 ) ,
@@ -146,9 +143,7 @@ where
146143 if self . next_refresh <= now {
147144 match S :: try_from ( & self . inner ) {
148145 Ok ( stats) => {
149- if let Err ( e) = self . sender . send ( Arc :: new ( stats) ) {
150- tracing:: error!( err = ?e, "failed to update transport stats" ) ;
151- }
146+ * self . stats . write ( ) . unwrap ( ) = Arc :: new ( stats) ;
152147 }
153148 Err ( e) => tracing:: error!( errror = ?e, "failed to gather transport stats" ) ,
154149 }
0 commit comments