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

[sctp] Include buffer size in ErrShortBuffer #456

Merged
merged 3 commits into from
Jun 12, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
6 changes: 3 additions & 3 deletions sctp/src/association/association_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -740,12 +740,12 @@ async fn test_assoc_reliable_short_buffer() -> Result<()> {

let mut buf = vec![0u8; 3];
let result = s1.read_sctp(&mut buf).await;
assert!(result.is_err(), "expected error to be io.ErrShortBuffer");
assert!(result.is_err(), "expected error to be ErrShortBuffer");
if let Err(err) = result {
assert_eq!(
err,
Error::ErrShortBuffer,
"expected error to be io.ErrShortBuffer"
Error::ErrShortBuffer { size: 3 },
"expected error to be ErrShortBuffer"
);
}

Expand Down
4 changes: 2 additions & 2 deletions sctp/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,8 +209,8 @@ pub enum Error {
ErrOutboundPacketTooLarge,
#[error("Stream closed")]
ErrStreamClosed,
#[error("Short buffer to be filled")]
ErrShortBuffer,
#[error("Short buffer (size: {size:?}) to be filled")]
ErrShortBuffer { size: usize },
#[error("Io EOF")]
ErrEof,
#[error("Invalid SystemTime")]
Expand Down
6 changes: 5 additions & 1 deletion sctp/src/queue/queue_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -795,7 +795,11 @@ fn test_reassembly_queue_detect_buffer_too_short() -> Result<()> {
let result = rq.read(&mut buf);
assert!(result.is_err(), "read() should not succeed");
if let Err(err) = result {
assert_eq!(err, Error::ErrShortBuffer, "read() should not succeed");
assert_eq!(
err,
Error::ErrShortBuffer { size: 8 },
"read() should not succeed"
);
}
assert_eq!(rq.get_num_bytes(), 0, "num bytes mismatch");

Expand Down
2 changes: 1 addition & 1 deletion sctp/src/queue/reassembly_queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ impl ReassemblyQueue {
buf[n_written..n_written + n].copy_from_slice(&c.user_data[..n]);
n_written += n;
if n < to_copy {
err = Some(Error::ErrShortBuffer);
err = Some(Error::ErrShortBuffer { size: buf.len() });
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion sctp/src/stream/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ impl Stream {
};

match result {
Ok(_) | Err(Error::ErrShortBuffer) => return result,
Ok(_) | Err(Error::ErrShortBuffer { .. }) => return result,
Err(_) => {
// wait for the next chunk to become available
self.read_notifier.notified().await;
Expand Down