Skip to content

Commit

Permalink
change get_stats to return Result
Browse files Browse the repository at this point in the history
  • Loading branch information
youyuanwu committed Jan 22, 2025
1 parent 2c51a2e commit a412ef7
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1532,7 +1532,7 @@ impl Connection {
}
}

pub fn get_stats(&self) -> QuicStatistics {
pub fn get_stats(&self) -> Result<QuicStatistics, Error> {
let mut stat_buffer: [u8; std::mem::size_of::<QuicStatistics>()] =
[0; std::mem::size_of::<QuicStatistics>()];
let stat_size_mut = std::mem::size_of::<QuicStatistics>();
Expand All @@ -1543,12 +1543,11 @@ impl Connection {
(&stat_size_mut) as *const usize as *const u32 as *mut u32,
stat_buffer.as_mut_ptr() as *mut c_void,
)
}
.expect("fail to get stats");
unsafe { *(stat_buffer.as_ptr() as *const c_void as *const QuicStatistics) }
}?;
Ok(unsafe { *(stat_buffer.as_ptr() as *const c_void as *const QuicStatistics) })
}

pub fn get_stats_v2(&self) -> QuicStatisticsV2 {
pub fn get_stats_v2(&self) -> Result<QuicStatisticsV2, Error> {
let mut stat_buffer: [u8; std::mem::size_of::<QuicStatisticsV2>()] =
[0; std::mem::size_of::<QuicStatisticsV2>()];
let stat_size_mut = std::mem::size_of::<QuicStatisticsV2>();
Expand All @@ -1559,10 +1558,8 @@ impl Connection {
(&stat_size_mut) as *const usize as *const u32 as *mut u32,
stat_buffer.as_mut_ptr() as *mut c_void,
)
}
.expect("fail to get stats v2");

unsafe { *(stat_buffer.as_ptr() as *const c_void as *const QuicStatisticsV2) }
}?;
Ok(unsafe { *(stat_buffer.as_ptr() as *const c_void as *const QuicStatisticsV2) })
}

pub fn set_configuration(&self, configuration: &Configuration) -> Result<(), Error> {
Expand Down

0 comments on commit a412ef7

Please sign in to comment.