Skip to content

Commit

Permalink
Merge pull request #456 from webrtc-rs/anton/273-partial-read-2
Browse files Browse the repository at this point in the history
[sctp] Include buffer size in `ErrShortBuffer`
  • Loading branch information
yngrtc authored Jun 12, 2023
2 parents 8168625 + 3cae751 commit c472e6d
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 8 deletions.
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

0 comments on commit c472e6d

Please sign in to comment.