Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rust: Migrate to use ffi QUIC_API_TABLE #4756

Merged
merged 4 commits into from
Jan 27, 2025
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 13 additions & 25 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,34 +102,24 @@ impl Error {
}

/// Convert from raw ffi error type.
pub fn from_raw(ec: QUIC_ERROR) -> Self {
Self(ec)
}

/// Temp api to use in manually written ffi code which is going to be
/// removed and replaced by auto generated ffi code.
/// This api will be replaced by from_raw.
pub fn from_u32(ec: u32) -> Self {
Self(ec as QUIC_ERROR)
pub fn ok_from_raw(ec: QUIC_ERROR) -> Result<(), Self> {
let e = Self(ec);
if e.is_ok() {
Ok(())
} else {
Err(e)
}
}

/// Return Err if the error is considered a failure.
/// Ok includes both "no error" and "pending" status codes.
pub fn ok(self) -> Result<(), Self> {
pub fn is_ok(&self) -> bool {
// on windows it is signed.
#[cfg(target_os = "windows")]
if self.0 < 0 {
Err(self)
} else {
Ok(())
}
return self.0 >= 0;

#[cfg(not(target_os = "windows"))]
if (self.0 as i32) > 0 {
Err(self)
} else {
Ok(())
}
return self.0 as i32 <= 0;
}
}

Expand Down Expand Up @@ -201,10 +191,8 @@ mod tests {

#[test]
fn error_ok_test() {
assert!(Error::new(ErrorCode::QUIC_ERROR_ABORTED).ok().is_err());
assert!(Error::new(ErrorCode::QUIC_ERROR_SUCCESS).ok().is_ok());
assert!(Error::from_raw(ErrorCode::QUIC_ERROR_PENDING as QUIC_ERROR)
.ok()
.is_ok());
assert!(!Error::new(ErrorCode::QUIC_ERROR_ABORTED).is_ok());
assert!(Error::new(ErrorCode::QUIC_ERROR_SUCCESS).is_ok());
assert!(Error::ok_from_raw(ErrorCode::QUIC_ERROR_PENDING as QUIC_ERROR).is_ok());
}
}
6 changes: 6 additions & 0 deletions src/ffi/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,9 @@ include!("linux_bindings.rs");
pub type ADDRESS_FAMILY = u16;
#[cfg(target_os = "windows")]
include!("win_bindings.rs");

/// Temp type for casting manual ffi flags. To be removed eventually.
#[cfg(not(target_os = "windows"))]
pub type QuicFlag = u32;
#[cfg(target_os = "windows")]
pub type QuicFlag = i32;
Loading
Loading