Skip to content

Commit 5ffccc0

Browse files
committed
Merge branch 'main' into user/sm/address_init
2 parents a91827b + 451c1a8 commit 5ffccc0

File tree

6 files changed

+88
-93
lines changed

6 files changed

+88
-93
lines changed

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ cmake = "0.1"
5757
bindgen = { version = "0.71", optional = true }
5858

5959
[dependencies]
60-
bitfield = "0.17.0"
60+
bitfield = "0.18.1"
6161
libc = "0.2.0"
6262
c-types = "4.0.0"
6363
serde = { version = "1.0.117", features = ["derive"] }

docs/Sample.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ By default, the server listens on port 4567.
3030
Start the client providing the IP address for the server. Here 127.0.0.1 is used as an example.
3131

3232
```Powershell
33-
quicsample.exe -client -unsecure -target:{127.0.0.1}
33+
quicsample.exe -client -unsecure -target:127.0.0.1
3434
```
3535

3636
## Troubleshooting with Wireshark

src/error.rs

+22-21
Original file line numberDiff line numberDiff line change
@@ -85,23 +85,24 @@ impl core::fmt::Display for StatusCode {
8585
}
8686
}
8787

88-
/// Quic error used in non-ffi code.
88+
/// Quic status used in non-ffi code.
8989
/// Internal representation matches the os platfrom type.
90+
/// Used for all non-ffi error return and callback status code fields.
9091
#[derive(Clone)]
91-
pub struct Error(pub QUIC_STATUS);
92+
pub struct Status(pub QUIC_STATUS);
9293

93-
impl Error {
94-
/// Create an error from enum.
94+
impl Status {
95+
/// Create an status from enum.
9596
pub fn new(ec: StatusCode) -> Self {
9697
Self(ec as QUIC_STATUS)
9798
}
98-
/// Convert to error code if possible.
99-
pub fn try_as_error_code(&self) -> Result<StatusCode, &str> {
99+
/// Convert to status code if possible.
100+
pub fn try_as_status_code(&self) -> Result<StatusCode, &str> {
100101
use std::convert::TryFrom;
101102
StatusCode::try_from(self.0 as QUIC_STATUS)
102103
}
103104

104-
/// Convert from raw ffi error type.
105+
/// Convert from raw ffi status type.
105106
pub fn ok_from_raw(ec: QUIC_STATUS) -> Result<(), Self> {
106107
let e = Self(ec);
107108
if e.is_ok() {
@@ -111,7 +112,7 @@ impl Error {
111112
}
112113
}
113114

114-
/// Return Err if the error is considered a failure.
115+
/// Return Err if the status is considered a failure.
115116
/// Ok includes both "no error" and "pending" status codes.
116117
pub fn is_ok(&self) -> bool {
117118
// on windows it is signed.
@@ -123,25 +124,25 @@ impl Error {
123124
}
124125
}
125126

126-
impl std::error::Error for Error {}
127+
impl std::error::Error for Status {}
127128

128-
impl From<QUIC_STATUS> for Error {
129+
impl From<QUIC_STATUS> for Status {
129130
fn from(value: QUIC_STATUS) -> Self {
130131
Self(value)
131132
}
132133
}
133134

134-
impl From<StatusCode> for Error {
135+
impl From<StatusCode> for Status {
135136
fn from(value: StatusCode) -> Self {
136137
Self::new(value)
137138
}
138139
}
139140

140141
/// The debug message is in the same format as error in windows crate.
141-
impl core::fmt::Debug for Error {
142+
impl core::fmt::Debug for Status {
142143
fn fmt(&self, fmt: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
143144
let mut debug = fmt.debug_struct("Error");
144-
let str_code = match self.try_as_error_code() {
145+
let str_code = match self.try_as_status_code() {
145146
Ok(c) => Some(c),
146147
Err(_) => None,
147148
};
@@ -155,9 +156,9 @@ impl core::fmt::Debug for Error {
155156
}
156157

157158
/// The display message is in the same format as error in windows crate.
158-
impl core::fmt::Display for Error {
159+
impl core::fmt::Display for Status {
159160
fn fmt(&self, fmt: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
160-
let str_code = match self.try_as_error_code() {
161+
let str_code = match self.try_as_status_code() {
161162
Ok(c) => Some(c),
162163
Err(_) => None,
163164
};
@@ -172,11 +173,11 @@ impl core::fmt::Display for Error {
172173
mod tests {
173174
use crate::ffi::QUIC_STATUS;
174175

175-
use super::{Error, StatusCode};
176+
use super::{Status, StatusCode};
176177

177178
#[test]
178179
fn error_fmt_test() {
179-
let err = Error::new(StatusCode::QUIC_STATUS_ABORTED);
180+
let err = Status::new(StatusCode::QUIC_STATUS_ABORTED);
180181
// message is platform dependent.
181182
#[cfg(target_os = "windows")]
182183
assert_eq!(format!("{err}"), "QUIC_STATUS_ABORTED (0x80004004)");
@@ -185,14 +186,14 @@ mod tests {
185186
format!("{err:?}"),
186187
"Error { code: 0x80004004, message: QUIC_STATUS_ABORTED }"
187188
);
188-
let ec = err.try_as_error_code().unwrap();
189+
let ec = err.try_as_status_code().unwrap();
189190
assert_eq!(format!("{ec}"), "QUIC_STATUS_ABORTED");
190191
}
191192

192193
#[test]
193194
fn error_ok_test() {
194-
assert!(!Error::new(StatusCode::QUIC_STATUS_ABORTED).is_ok());
195-
assert!(Error::new(StatusCode::QUIC_STATUS_SUCCESS).is_ok());
196-
assert!(Error::ok_from_raw(StatusCode::QUIC_STATUS_PENDING as QUIC_STATUS).is_ok());
195+
assert!(!Status::new(StatusCode::QUIC_STATUS_ABORTED).is_ok());
196+
assert!(Status::new(StatusCode::QUIC_STATUS_SUCCESS).is_ok());
197+
assert!(Status::ok_from_raw(StatusCode::QUIC_STATUS_PENDING as QUIC_STATUS).is_ok());
197198
}
198199
}

0 commit comments

Comments
 (0)