зеркало из https://github.com/microsoft/msquic.git
Rust: Rename QUIC_ERROR to QUIC_STATUS (#4765)
This commit is contained in:
Родитель
0781de50d8
Коммит
71ae53bebe
132
src/error.rs
132
src/error.rs
|
@ -1,17 +1,17 @@
|
|||
// Copyright (c) Microsoft Corporation.
|
||||
// Licensed under the MIT License.
|
||||
|
||||
use crate::ffi::QUIC_ERROR;
|
||||
use crate::ffi::QUIC_STATUS;
|
||||
|
||||
/// Defines quic error code enum and its conversion
|
||||
/// Defines quic error status enum and its conversion
|
||||
/// to raw type using macro.
|
||||
macro_rules! define_quic_error_code{
|
||||
macro_rules! define_quic_status_code{
|
||||
($( $code1:ident ),*) =>{
|
||||
/// Enum of quic status codes.
|
||||
#[allow(non_camel_case_types)]
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
#[repr(u32)]
|
||||
pub enum ErrorCode {
|
||||
pub enum StatusCode {
|
||||
$(
|
||||
$code1 = crate::ffi::$code1 as u32,
|
||||
)*
|
||||
|
@ -19,14 +19,14 @@ macro_rules! define_quic_error_code{
|
|||
|
||||
/// Convert from ffi type to enum.
|
||||
/// Conversion failes when the status value is not a quic status.
|
||||
impl std::convert::TryFrom<crate::ffi::QUIC_ERROR> for ErrorCode {
|
||||
impl std::convert::TryFrom<crate::ffi::QUIC_STATUS> for StatusCode {
|
||||
type Error = &'static str;
|
||||
fn try_from(value: crate::ffi::QUIC_ERROR) -> Result<Self, Self::Error> {
|
||||
fn try_from(value: crate::ffi::QUIC_STATUS) -> Result<Self, Self::Error> {
|
||||
match value {
|
||||
$(
|
||||
crate::ffi::$code1 => Ok(Self::$code1),
|
||||
)*
|
||||
_ => Err("Unknown QUIC_ERROR")
|
||||
_ => Err("Unknown QUIC_STATUS")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -34,52 +34,52 @@ macro_rules! define_quic_error_code{
|
|||
}
|
||||
|
||||
// defines all quic error codes.
|
||||
define_quic_error_code!(
|
||||
QUIC_ERROR_SUCCESS,
|
||||
QUIC_ERROR_PENDING,
|
||||
QUIC_ERROR_CONTINUE,
|
||||
QUIC_ERROR_OUT_OF_MEMORY,
|
||||
QUIC_ERROR_INVALID_PARAMETER,
|
||||
QUIC_ERROR_INVALID_STATE,
|
||||
QUIC_ERROR_NOT_SUPPORTED,
|
||||
QUIC_ERROR_NOT_FOUND,
|
||||
QUIC_ERROR_BUFFER_TOO_SMALL,
|
||||
QUIC_ERROR_HANDSHAKE_FAILURE,
|
||||
QUIC_ERROR_ABORTED,
|
||||
QUIC_ERROR_ADDRESS_IN_USE,
|
||||
QUIC_ERROR_INVALID_ADDRESS,
|
||||
QUIC_ERROR_CONNECTION_TIMEOUT,
|
||||
QUIC_ERROR_CONNECTION_IDLE,
|
||||
QUIC_ERROR_UNREACHABLE,
|
||||
QUIC_ERROR_INTERNAL_ERROR,
|
||||
QUIC_ERROR_CONNECTION_REFUSED,
|
||||
QUIC_ERROR_PROTOCOL_ERROR,
|
||||
QUIC_ERROR_VER_NEG_ERROR,
|
||||
QUIC_ERROR_TLS_ERROR,
|
||||
QUIC_ERROR_USER_CANCELED,
|
||||
QUIC_ERROR_ALPN_NEG_FAILURE,
|
||||
QUIC_ERROR_STREAM_LIMIT_REACHED,
|
||||
QUIC_ERROR_ALPN_IN_USE,
|
||||
QUIC_ERROR_CLOSE_NOTIFY,
|
||||
QUIC_ERROR_BAD_CERTIFICATE,
|
||||
QUIC_ERROR_UNSUPPORTED_CERTIFICATE,
|
||||
QUIC_ERROR_REVOKED_CERTIFICATE,
|
||||
QUIC_ERROR_EXPIRED_CERTIFICATE,
|
||||
QUIC_ERROR_UNKNOWN_CERTIFICATE,
|
||||
QUIC_ERROR_REQUIRED_CERTIFICATE,
|
||||
QUIC_ERROR_CERT_EXPIRED,
|
||||
QUIC_ERROR_CERT_UNTRUSTED_ROOT,
|
||||
QUIC_ERROR_CERT_NO_CERT
|
||||
define_quic_status_code!(
|
||||
QUIC_STATUS_SUCCESS,
|
||||
QUIC_STATUS_PENDING,
|
||||
QUIC_STATUS_CONTINUE,
|
||||
QUIC_STATUS_OUT_OF_MEMORY,
|
||||
QUIC_STATUS_INVALID_PARAMETER,
|
||||
QUIC_STATUS_INVALID_STATE,
|
||||
QUIC_STATUS_NOT_SUPPORTED,
|
||||
QUIC_STATUS_NOT_FOUND,
|
||||
QUIC_STATUS_BUFFER_TOO_SMALL,
|
||||
QUIC_STATUS_HANDSHAKE_FAILURE,
|
||||
QUIC_STATUS_ABORTED,
|
||||
QUIC_STATUS_ADDRESS_IN_USE,
|
||||
QUIC_STATUS_INVALID_ADDRESS,
|
||||
QUIC_STATUS_CONNECTION_TIMEOUT,
|
||||
QUIC_STATUS_CONNECTION_IDLE,
|
||||
QUIC_STATUS_UNREACHABLE,
|
||||
QUIC_STATUS_INTERNAL_ERROR,
|
||||
QUIC_STATUS_CONNECTION_REFUSED,
|
||||
QUIC_STATUS_PROTOCOL_ERROR,
|
||||
QUIC_STATUS_VER_NEG_ERROR,
|
||||
QUIC_STATUS_TLS_ERROR,
|
||||
QUIC_STATUS_USER_CANCELED,
|
||||
QUIC_STATUS_ALPN_NEG_FAILURE,
|
||||
QUIC_STATUS_STREAM_LIMIT_REACHED,
|
||||
QUIC_STATUS_ALPN_IN_USE,
|
||||
QUIC_STATUS_CLOSE_NOTIFY,
|
||||
QUIC_STATUS_BAD_CERTIFICATE,
|
||||
QUIC_STATUS_UNSUPPORTED_CERTIFICATE,
|
||||
QUIC_STATUS_REVOKED_CERTIFICATE,
|
||||
QUIC_STATUS_EXPIRED_CERTIFICATE,
|
||||
QUIC_STATUS_UNKNOWN_CERTIFICATE,
|
||||
QUIC_STATUS_REQUIRED_CERTIFICATE,
|
||||
QUIC_STATUS_CERT_EXPIRED,
|
||||
QUIC_STATUS_CERT_UNTRUSTED_ROOT,
|
||||
QUIC_STATUS_CERT_NO_CERT
|
||||
);
|
||||
|
||||
impl From<ErrorCode> for QUIC_ERROR {
|
||||
fn from(value: ErrorCode) -> Self {
|
||||
value as QUIC_ERROR
|
||||
impl From<StatusCode> for QUIC_STATUS {
|
||||
fn from(value: StatusCode) -> Self {
|
||||
value as QUIC_STATUS
|
||||
}
|
||||
}
|
||||
|
||||
/// The display string is the same as the debug string, i.e. the enum string.
|
||||
impl core::fmt::Display for ErrorCode {
|
||||
impl core::fmt::Display for StatusCode {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
core::write!(f, "{:?}", self)
|
||||
}
|
||||
|
@ -88,21 +88,21 @@ impl core::fmt::Display for ErrorCode {
|
|||
/// Quic error used in non-ffi code.
|
||||
/// Internal representation matches the os platfrom type.
|
||||
#[derive(Clone)]
|
||||
pub struct Error(pub QUIC_ERROR);
|
||||
pub struct Error(pub QUIC_STATUS);
|
||||
|
||||
impl Error {
|
||||
/// Create an error from enum.
|
||||
pub fn new(ec: ErrorCode) -> Self {
|
||||
Self(ec as QUIC_ERROR)
|
||||
pub fn new(ec: StatusCode) -> Self {
|
||||
Self(ec as QUIC_STATUS)
|
||||
}
|
||||
/// Convert to error code if possible.
|
||||
pub fn try_as_error_code(&self) -> Result<ErrorCode, &str> {
|
||||
pub fn try_as_error_code(&self) -> Result<StatusCode, &str> {
|
||||
use std::convert::TryFrom;
|
||||
ErrorCode::try_from(self.0 as QUIC_ERROR)
|
||||
StatusCode::try_from(self.0 as QUIC_STATUS)
|
||||
}
|
||||
|
||||
/// Convert from raw ffi error type.
|
||||
pub fn ok_from_raw(ec: QUIC_ERROR) -> Result<(), Self> {
|
||||
pub fn ok_from_raw(ec: QUIC_STATUS) -> Result<(), Self> {
|
||||
let e = Self(ec);
|
||||
if e.is_ok() {
|
||||
Ok(())
|
||||
|
@ -125,14 +125,14 @@ impl Error {
|
|||
|
||||
impl std::error::Error for Error {}
|
||||
|
||||
impl From<QUIC_ERROR> for Error {
|
||||
fn from(value: QUIC_ERROR) -> Self {
|
||||
impl From<QUIC_STATUS> for Error {
|
||||
fn from(value: QUIC_STATUS) -> Self {
|
||||
Self(value)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<ErrorCode> for Error {
|
||||
fn from(value: ErrorCode) -> Self {
|
||||
impl From<StatusCode> for Error {
|
||||
fn from(value: StatusCode) -> Self {
|
||||
Self::new(value)
|
||||
}
|
||||
}
|
||||
|
@ -170,29 +170,29 @@ impl core::fmt::Display for Error {
|
|||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::ffi::QUIC_ERROR;
|
||||
use crate::ffi::QUIC_STATUS;
|
||||
|
||||
use super::{Error, ErrorCode};
|
||||
use super::{Error, StatusCode};
|
||||
|
||||
#[test]
|
||||
fn error_fmt_test() {
|
||||
let err = Error::new(ErrorCode::QUIC_ERROR_ABORTED);
|
||||
let err = Error::new(StatusCode::QUIC_STATUS_ABORTED);
|
||||
// message is platform dependent.
|
||||
#[cfg(target_os = "windows")]
|
||||
assert_eq!(format!("{err}"), "QUIC_ERROR_ABORTED (0x80004004)");
|
||||
assert_eq!(format!("{err}"), "QUIC_STATUS_ABORTED (0x80004004)");
|
||||
#[cfg(target_os = "windows")]
|
||||
assert_eq!(
|
||||
format!("{err:?}"),
|
||||
"Error { code: 0x80004004, message: QUIC_ERROR_ABORTED }"
|
||||
"Error { code: 0x80004004, message: QUIC_STATUS_ABORTED }"
|
||||
);
|
||||
let ec = err.try_as_error_code().unwrap();
|
||||
assert_eq!(format!("{ec}"), "QUIC_ERROR_ABORTED");
|
||||
assert_eq!(format!("{ec}"), "QUIC_STATUS_ABORTED");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn error_ok_test() {
|
||||
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());
|
||||
assert!(!Error::new(StatusCode::QUIC_STATUS_ABORTED).is_ok());
|
||||
assert!(Error::new(StatusCode::QUIC_STATUS_SUCCESS).is_ok());
|
||||
assert!(Error::ok_from_raw(StatusCode::QUIC_STATUS_PENDING as QUIC_STATUS).is_ok());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5658,39 +5658,39 @@ const _: () = {
|
|||
ConnectionCertificateValidationComplete
|
||||
) - 240usize];
|
||||
};
|
||||
pub const QUIC_ERROR_SUCCESS: QUIC_ERROR = 0;
|
||||
pub const QUIC_ERROR_PENDING: QUIC_ERROR = 4294967294;
|
||||
pub const QUIC_ERROR_CONTINUE: QUIC_ERROR = 4294967295;
|
||||
pub const QUIC_ERROR_OUT_OF_MEMORY: QUIC_ERROR = 12;
|
||||
pub const QUIC_ERROR_INVALID_PARAMETER: QUIC_ERROR = 22;
|
||||
pub const QUIC_ERROR_INVALID_STATE: QUIC_ERROR = 1;
|
||||
pub const QUIC_ERROR_NOT_SUPPORTED: QUIC_ERROR = 95;
|
||||
pub const QUIC_ERROR_NOT_FOUND: QUIC_ERROR = 2;
|
||||
pub const QUIC_ERROR_BUFFER_TOO_SMALL: QUIC_ERROR = 75;
|
||||
pub const QUIC_ERROR_HANDSHAKE_FAILURE: QUIC_ERROR = 103;
|
||||
pub const QUIC_ERROR_ABORTED: QUIC_ERROR = 125;
|
||||
pub const QUIC_ERROR_ADDRESS_IN_USE: QUIC_ERROR = 98;
|
||||
pub const QUIC_ERROR_INVALID_ADDRESS: QUIC_ERROR = 97;
|
||||
pub const QUIC_ERROR_CONNECTION_TIMEOUT: QUIC_ERROR = 110;
|
||||
pub const QUIC_ERROR_CONNECTION_IDLE: QUIC_ERROR = 62;
|
||||
pub const QUIC_ERROR_UNREACHABLE: QUIC_ERROR = 113;
|
||||
pub const QUIC_ERROR_INTERNAL_ERROR: QUIC_ERROR = 5;
|
||||
pub const QUIC_ERROR_CONNECTION_REFUSED: QUIC_ERROR = 111;
|
||||
pub const QUIC_ERROR_PROTOCOL_ERROR: QUIC_ERROR = 71;
|
||||
pub const QUIC_ERROR_VER_NEG_ERROR: QUIC_ERROR = 93;
|
||||
pub const QUIC_ERROR_TLS_ERROR: QUIC_ERROR = 126;
|
||||
pub const QUIC_ERROR_USER_CANCELED: QUIC_ERROR = 130;
|
||||
pub const QUIC_ERROR_ALPN_NEG_FAILURE: QUIC_ERROR = 92;
|
||||
pub const QUIC_ERROR_STREAM_LIMIT_REACHED: QUIC_ERROR = 86;
|
||||
pub const QUIC_ERROR_ALPN_IN_USE: QUIC_ERROR = 91;
|
||||
pub const QUIC_ERROR_CLOSE_NOTIFY: QUIC_ERROR = 200000256;
|
||||
pub const QUIC_ERROR_BAD_CERTIFICATE: QUIC_ERROR = 200000298;
|
||||
pub const QUIC_ERROR_UNSUPPORTED_CERTIFICATE: QUIC_ERROR = 200000299;
|
||||
pub const QUIC_ERROR_REVOKED_CERTIFICATE: QUIC_ERROR = 200000300;
|
||||
pub const QUIC_ERROR_EXPIRED_CERTIFICATE: QUIC_ERROR = 200000301;
|
||||
pub const QUIC_ERROR_UNKNOWN_CERTIFICATE: QUIC_ERROR = 200000302;
|
||||
pub const QUIC_ERROR_REQUIRED_CERTIFICATE: QUIC_ERROR = 200000372;
|
||||
pub const QUIC_ERROR_CERT_EXPIRED: QUIC_ERROR = 200000513;
|
||||
pub const QUIC_ERROR_CERT_UNTRUSTED_ROOT: QUIC_ERROR = 200000514;
|
||||
pub const QUIC_ERROR_CERT_NO_CERT: QUIC_ERROR = 200000515;
|
||||
pub type QUIC_ERROR = ::std::os::raw::c_uint;
|
||||
pub const QUIC_STATUS_SUCCESS: QUIC_STATUS = 0;
|
||||
pub const QUIC_STATUS_PENDING: QUIC_STATUS = 4294967294;
|
||||
pub const QUIC_STATUS_CONTINUE: QUIC_STATUS = 4294967295;
|
||||
pub const QUIC_STATUS_OUT_OF_MEMORY: QUIC_STATUS = 12;
|
||||
pub const QUIC_STATUS_INVALID_PARAMETER: QUIC_STATUS = 22;
|
||||
pub const QUIC_STATUS_INVALID_STATE: QUIC_STATUS = 1;
|
||||
pub const QUIC_STATUS_NOT_SUPPORTED: QUIC_STATUS = 95;
|
||||
pub const QUIC_STATUS_NOT_FOUND: QUIC_STATUS = 2;
|
||||
pub const QUIC_STATUS_BUFFER_TOO_SMALL: QUIC_STATUS = 75;
|
||||
pub const QUIC_STATUS_HANDSHAKE_FAILURE: QUIC_STATUS = 103;
|
||||
pub const QUIC_STATUS_ABORTED: QUIC_STATUS = 125;
|
||||
pub const QUIC_STATUS_ADDRESS_IN_USE: QUIC_STATUS = 98;
|
||||
pub const QUIC_STATUS_INVALID_ADDRESS: QUIC_STATUS = 97;
|
||||
pub const QUIC_STATUS_CONNECTION_TIMEOUT: QUIC_STATUS = 110;
|
||||
pub const QUIC_STATUS_CONNECTION_IDLE: QUIC_STATUS = 62;
|
||||
pub const QUIC_STATUS_UNREACHABLE: QUIC_STATUS = 113;
|
||||
pub const QUIC_STATUS_INTERNAL_ERROR: QUIC_STATUS = 5;
|
||||
pub const QUIC_STATUS_CONNECTION_REFUSED: QUIC_STATUS = 111;
|
||||
pub const QUIC_STATUS_PROTOCOL_ERROR: QUIC_STATUS = 71;
|
||||
pub const QUIC_STATUS_VER_NEG_ERROR: QUIC_STATUS = 93;
|
||||
pub const QUIC_STATUS_TLS_ERROR: QUIC_STATUS = 126;
|
||||
pub const QUIC_STATUS_USER_CANCELED: QUIC_STATUS = 130;
|
||||
pub const QUIC_STATUS_ALPN_NEG_FAILURE: QUIC_STATUS = 92;
|
||||
pub const QUIC_STATUS_STREAM_LIMIT_REACHED: QUIC_STATUS = 86;
|
||||
pub const QUIC_STATUS_ALPN_IN_USE: QUIC_STATUS = 91;
|
||||
pub const QUIC_STATUS_CLOSE_NOTIFY: QUIC_STATUS = 200000256;
|
||||
pub const QUIC_STATUS_BAD_CERTIFICATE: QUIC_STATUS = 200000298;
|
||||
pub const QUIC_STATUS_UNSUPPORTED_CERTIFICATE: QUIC_STATUS = 200000299;
|
||||
pub const QUIC_STATUS_REVOKED_CERTIFICATE: QUIC_STATUS = 200000300;
|
||||
pub const QUIC_STATUS_EXPIRED_CERTIFICATE: QUIC_STATUS = 200000301;
|
||||
pub const QUIC_STATUS_UNKNOWN_CERTIFICATE: QUIC_STATUS = 200000302;
|
||||
pub const QUIC_STATUS_REQUIRED_CERTIFICATE: QUIC_STATUS = 200000372;
|
||||
pub const QUIC_STATUS_CERT_EXPIRED: QUIC_STATUS = 200000513;
|
||||
pub const QUIC_STATUS_CERT_UNTRUSTED_ROOT: QUIC_STATUS = 200000514;
|
||||
pub const QUIC_STATUS_CERT_NO_CERT: QUIC_STATUS = 200000515;
|
||||
pub type QUIC_STATUS = ::std::os::raw::c_uint;
|
||||
|
|
|
@ -5683,39 +5683,39 @@ const _: () = {
|
|||
ConnectionCertificateValidationComplete
|
||||
) - 240usize];
|
||||
};
|
||||
pub const QUIC_ERROR_SUCCESS: QUIC_ERROR = 0;
|
||||
pub const QUIC_ERROR_PENDING: QUIC_ERROR = 459749;
|
||||
pub const QUIC_ERROR_CONTINUE: QUIC_ERROR = 459998;
|
||||
pub const QUIC_ERROR_OUT_OF_MEMORY: QUIC_ERROR = -2147024882;
|
||||
pub const QUIC_ERROR_INVALID_PARAMETER: QUIC_ERROR = -2147024809;
|
||||
pub const QUIC_ERROR_INVALID_STATE: QUIC_ERROR = -2147019873;
|
||||
pub const QUIC_ERROR_NOT_SUPPORTED: QUIC_ERROR = -2147467262;
|
||||
pub const QUIC_ERROR_NOT_FOUND: QUIC_ERROR = -2147023728;
|
||||
pub const QUIC_ERROR_BUFFER_TOO_SMALL: QUIC_ERROR = -2147024774;
|
||||
pub const QUIC_ERROR_HANDSHAKE_FAILURE: QUIC_ERROR = -2143223808;
|
||||
pub const QUIC_ERROR_ABORTED: QUIC_ERROR = -2147467260;
|
||||
pub const QUIC_ERROR_ADDRESS_IN_USE: QUIC_ERROR = -2147014848;
|
||||
pub const QUIC_ERROR_INVALID_ADDRESS: QUIC_ERROR = -2147014847;
|
||||
pub const QUIC_ERROR_CONNECTION_TIMEOUT: QUIC_ERROR = -2143223802;
|
||||
pub const QUIC_ERROR_CONNECTION_IDLE: QUIC_ERROR = -2143223803;
|
||||
pub const QUIC_ERROR_UNREACHABLE: QUIC_ERROR = -2147023664;
|
||||
pub const QUIC_ERROR_INTERNAL_ERROR: QUIC_ERROR = -2143223805;
|
||||
pub const QUIC_ERROR_CONNECTION_REFUSED: QUIC_ERROR = -2147023671;
|
||||
pub const QUIC_ERROR_PROTOCOL_ERROR: QUIC_ERROR = -2143223804;
|
||||
pub const QUIC_ERROR_VER_NEG_ERROR: QUIC_ERROR = -2143223807;
|
||||
pub const QUIC_ERROR_TLS_ERROR: QUIC_ERROR = -2147013864;
|
||||
pub const QUIC_ERROR_USER_CANCELED: QUIC_ERROR = -2143223806;
|
||||
pub const QUIC_ERROR_ALPN_NEG_FAILURE: QUIC_ERROR = -2143223801;
|
||||
pub const QUIC_ERROR_STREAM_LIMIT_REACHED: QUIC_ERROR = -2143223800;
|
||||
pub const QUIC_ERROR_ALPN_IN_USE: QUIC_ERROR = -2143223799;
|
||||
pub const QUIC_ERROR_CLOSE_NOTIFY: QUIC_ERROR = -2143223552;
|
||||
pub const QUIC_ERROR_BAD_CERTIFICATE: QUIC_ERROR = -2143223510;
|
||||
pub const QUIC_ERROR_UNSUPPORTED_CERTIFICATE: QUIC_ERROR = -2143223509;
|
||||
pub const QUIC_ERROR_REVOKED_CERTIFICATE: QUIC_ERROR = -2143223508;
|
||||
pub const QUIC_ERROR_EXPIRED_CERTIFICATE: QUIC_ERROR = -2143223507;
|
||||
pub const QUIC_ERROR_UNKNOWN_CERTIFICATE: QUIC_ERROR = -2143223506;
|
||||
pub const QUIC_ERROR_REQUIRED_CERTIFICATE: QUIC_ERROR = -2143223436;
|
||||
pub const QUIC_ERROR_CERT_EXPIRED: QUIC_ERROR = -2146762495;
|
||||
pub const QUIC_ERROR_CERT_UNTRUSTED_ROOT: QUIC_ERROR = -2146762487;
|
||||
pub const QUIC_ERROR_CERT_NO_CERT: QUIC_ERROR = -2146893042;
|
||||
pub type QUIC_ERROR = ::std::os::raw::c_int;
|
||||
pub const QUIC_STATUS_SUCCESS: QUIC_STATUS = 0;
|
||||
pub const QUIC_STATUS_PENDING: QUIC_STATUS = 459749;
|
||||
pub const QUIC_STATUS_CONTINUE: QUIC_STATUS = 459998;
|
||||
pub const QUIC_STATUS_OUT_OF_MEMORY: QUIC_STATUS = -2147024882;
|
||||
pub const QUIC_STATUS_INVALID_PARAMETER: QUIC_STATUS = -2147024809;
|
||||
pub const QUIC_STATUS_INVALID_STATE: QUIC_STATUS = -2147019873;
|
||||
pub const QUIC_STATUS_NOT_SUPPORTED: QUIC_STATUS = -2147467262;
|
||||
pub const QUIC_STATUS_NOT_FOUND: QUIC_STATUS = -2147023728;
|
||||
pub const QUIC_STATUS_BUFFER_TOO_SMALL: QUIC_STATUS = -2147024774;
|
||||
pub const QUIC_STATUS_HANDSHAKE_FAILURE: QUIC_STATUS = -2143223808;
|
||||
pub const QUIC_STATUS_ABORTED: QUIC_STATUS = -2147467260;
|
||||
pub const QUIC_STATUS_ADDRESS_IN_USE: QUIC_STATUS = -2147014848;
|
||||
pub const QUIC_STATUS_INVALID_ADDRESS: QUIC_STATUS = -2147014847;
|
||||
pub const QUIC_STATUS_CONNECTION_TIMEOUT: QUIC_STATUS = -2143223802;
|
||||
pub const QUIC_STATUS_CONNECTION_IDLE: QUIC_STATUS = -2143223803;
|
||||
pub const QUIC_STATUS_UNREACHABLE: QUIC_STATUS = -2147023664;
|
||||
pub const QUIC_STATUS_INTERNAL_ERROR: QUIC_STATUS = -2143223805;
|
||||
pub const QUIC_STATUS_CONNECTION_REFUSED: QUIC_STATUS = -2147023671;
|
||||
pub const QUIC_STATUS_PROTOCOL_ERROR: QUIC_STATUS = -2143223804;
|
||||
pub const QUIC_STATUS_VER_NEG_ERROR: QUIC_STATUS = -2143223807;
|
||||
pub const QUIC_STATUS_TLS_ERROR: QUIC_STATUS = -2147013864;
|
||||
pub const QUIC_STATUS_USER_CANCELED: QUIC_STATUS = -2143223806;
|
||||
pub const QUIC_STATUS_ALPN_NEG_FAILURE: QUIC_STATUS = -2143223801;
|
||||
pub const QUIC_STATUS_STREAM_LIMIT_REACHED: QUIC_STATUS = -2143223800;
|
||||
pub const QUIC_STATUS_ALPN_IN_USE: QUIC_STATUS = -2143223799;
|
||||
pub const QUIC_STATUS_CLOSE_NOTIFY: QUIC_STATUS = -2143223552;
|
||||
pub const QUIC_STATUS_BAD_CERTIFICATE: QUIC_STATUS = -2143223510;
|
||||
pub const QUIC_STATUS_UNSUPPORTED_CERTIFICATE: QUIC_STATUS = -2143223509;
|
||||
pub const QUIC_STATUS_REVOKED_CERTIFICATE: QUIC_STATUS = -2143223508;
|
||||
pub const QUIC_STATUS_EXPIRED_CERTIFICATE: QUIC_STATUS = -2143223507;
|
||||
pub const QUIC_STATUS_UNKNOWN_CERTIFICATE: QUIC_STATUS = -2143223506;
|
||||
pub const QUIC_STATUS_REQUIRED_CERTIFICATE: QUIC_STATUS = -2143223436;
|
||||
pub const QUIC_STATUS_CERT_EXPIRED: QUIC_STATUS = -2146762495;
|
||||
pub const QUIC_STATUS_CERT_UNTRUSTED_ROOT: QUIC_STATUS = -2146762487;
|
||||
pub const QUIC_STATUS_CERT_NO_CERT: QUIC_STATUS = -2146893042;
|
||||
pub type QUIC_STATUS = ::std::os::raw::c_int;
|
||||
|
|
|
@ -2,10 +2,14 @@
|
|||
|
||||
#include "msquic.h"
|
||||
|
||||
// bindgen or clang has problem with c marcro functions
|
||||
// This forces clang to evaluate macros.
|
||||
// Cannot reuse QUIC_STATUS as the name because it is an macro type.
|
||||
typedef enum QUIC_ERROR {
|
||||
// undef the macro type and define the enum type.
|
||||
// This is ugly here but makes Rust code aligned with c code.
|
||||
#undef QUIC_STATUS
|
||||
typedef enum QUIC_STATUS {
|
||||
#ifndef _WIN32
|
||||
// on posix all status code relies on the macro type so we redefine it.
|
||||
#define QUIC_STATUS unsigned int
|
||||
#endif
|
||||
SUCCESS = QUIC_STATUS_SUCCESS,
|
||||
PENDING = QUIC_STATUS_PENDING,
|
||||
CONTINUE = QUIC_STATUS_CONTINUE,
|
||||
|
@ -41,4 +45,8 @@ typedef enum QUIC_ERROR {
|
|||
CERT_EXPIRED = QUIC_STATUS_CERT_EXPIRED,
|
||||
CERT_UNTRUSTED_ROOT = QUIC_STATUS_CERT_UNTRUSTED_ROOT,
|
||||
CERT_NO_CERT = QUIC_STATUS_CERT_NO_CERT
|
||||
} QUIC_ERROR;
|
||||
#ifndef _WIN32
|
||||
// posix need to undef the redefine.
|
||||
#undef QUIC_STATUS
|
||||
#endif
|
||||
} QUIC_STATUS;
|
||||
|
|
10
src/lib.rs
10
src/lib.rs
|
@ -8,7 +8,7 @@ use c_types::AF_INET6;
|
|||
#[allow(unused_imports)]
|
||||
use c_types::AF_UNSPEC;
|
||||
use c_types::{sa_family_t, sockaddr_in, sockaddr_in6, socklen_t};
|
||||
use ffi::{HQUIC, QUIC_API_TABLE, QUIC_BUFFER, QUIC_CREDENTIAL_CONFIG, QUIC_ERROR, QUIC_SETTINGS};
|
||||
use ffi::{HQUIC, QUIC_API_TABLE, QUIC_BUFFER, QUIC_CREDENTIAL_CONFIG, QUIC_SETTINGS, QUIC_STATUS};
|
||||
use libc::c_void;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use socket2::SockAddr;
|
||||
|
@ -25,7 +25,7 @@ use std::sync::Once;
|
|||
extern crate bitfield;
|
||||
mod error;
|
||||
pub mod ffi;
|
||||
pub use error::{Error, ErrorCode};
|
||||
pub use error::{Error, StatusCode};
|
||||
|
||||
//
|
||||
// The following starts the C interop layer of MsQuic API.
|
||||
|
@ -1134,7 +1134,7 @@ impl Api {
|
|||
START_MSQUIC.call_once(|| {
|
||||
let mut table: *const QUIC_API_TABLE = ptr::null();
|
||||
let status = MsQuicOpenVersion(2, std::ptr::addr_of_mut!(table));
|
||||
if let Err(err) = Error::ok_from_raw(status as QUIC_ERROR) {
|
||||
if let Err(err) = Error::ok_from_raw(status as QUIC_STATUS) {
|
||||
panic!("Failed to open MsQuic: {}", err);
|
||||
}
|
||||
APITABLE = table;
|
||||
|
@ -1849,7 +1849,7 @@ mod tests {
|
|||
use std::ffi::c_void;
|
||||
use std::ptr;
|
||||
|
||||
use crate::ffi::{HQUIC, QUIC_ERROR};
|
||||
use crate::ffi::{HQUIC, QUIC_STATUS};
|
||||
use crate::{
|
||||
ffi, Buffer, Configuration, Connection, ConnectionEvent, CredentialConfig, Registration,
|
||||
Settings, Stream, StreamEvent,
|
||||
|
@ -1859,7 +1859,7 @@ mod tests {
|
|||
_connection: HQUIC,
|
||||
context: *mut c_void,
|
||||
event: *mut ffi::QUIC_CONNECTION_EVENT,
|
||||
) -> QUIC_ERROR {
|
||||
) -> QUIC_STATUS {
|
||||
let connection = unsafe { &*(context as *const Connection) };
|
||||
let event = unsafe { (event as *const ConnectionEvent).as_ref().unwrap() };
|
||||
match event.event_type {
|
||||
|
|
Загрузка…
Ссылка в новой задаче