File tree Expand file tree Collapse file tree 1 file changed +7
-2
lines changed
examples/examples/data-channels-flow-control Expand file tree Collapse file tree 1 file changed +7
-2
lines changed Original file line number Diff line number Diff line change @@ -117,23 +117,28 @@ async fn create_responder() -> anyhow::Result<RTCPeerConnection> {
117
117
Box :: pin ( async {
118
118
// This callback shouldn't be blocked for a long time, so we spawn our handler
119
119
tokio:: spawn ( async move {
120
- let start = SystemTime :: now ( ) ;
120
+ let mut start = SystemTime :: now ( ) ;
121
+ let mut last_total_bytes_received: usize = 0 ;
121
122
122
123
tokio:: time:: sleep ( Duration :: from_secs ( 1 ) ) . await ;
123
124
println ! ( ) ;
124
125
125
126
loop {
126
127
let total_bytes_received =
127
128
shared_total_bytes_received. load ( Ordering :: Relaxed ) ;
129
+ let epoch_bytes_received =
130
+ total_bytes_received - last_total_bytes_received;
131
+ last_total_bytes_received = total_bytes_received;
128
132
129
133
let elapsed = SystemTime :: now ( ) . duration_since ( start) ;
130
134
let bps =
131
- ( total_bytes_received * 8 ) as f64 / elapsed. unwrap ( ) . as_secs_f64 ( ) ;
135
+ ( epoch_bytes_received * 8 ) as f64 / elapsed. unwrap ( ) . as_secs_f64 ( ) ;
132
136
133
137
println ! (
134
138
"Throughput is about {:.03} Mbps" ,
135
139
bps / ( 1024 * 1024 ) as f64
136
140
) ;
141
+ start = SystemTime :: now ( ) ;
137
142
tokio:: time:: sleep ( Duration :: from_secs ( 1 ) ) . await ;
138
143
}
139
144
} ) ;
You can’t perform that action at this time.
0 commit comments