Skip to content

Commit

Permalink
Update some comments about stream (Tencent#368)
Browse files Browse the repository at this point in the history
  • Loading branch information
iyangsj authored Aug 16, 2024
1 parent 14de90e commit 4046a48
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/connection/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3666,7 +3666,7 @@ impl Connection {
}
}

/// Return an iterator over streams that have data to read.
/// Return an iterator over streams that have data to read or an error to collect.
pub fn stream_readable_iter(&self) -> StreamIter {
self.streams.readable_iter()
}
Expand Down Expand Up @@ -3794,7 +3794,7 @@ impl Connection {
self.streams.stream_writable(stream_id, len)
}

/// Return true if the stream has data that can be read.
/// Return true if the stream has data to be read or an error to be collected.
pub fn stream_readable(&self, stream_id: u64) -> bool {
self.streams.stream_readable(stream_id)
}
Expand Down
16 changes: 10 additions & 6 deletions src/connection/stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,9 +235,7 @@ impl StreamMap {
/// Read contiguous data from the stream's receive buffer into the given buffer.
///
/// Return the number of bytes read and the `fin` flag if read successfully.
///
/// Return `StreamStateError` if the stream closed or never opened.
///
/// Return `Done` if the stream is not readable.
pub fn stream_read(&mut self, stream_id: u64, out: &mut [u8]) -> Result<(usize, bool)> {
// Local initiated unidirectional streams are send-only, so we can't read from them.
Expand Down Expand Up @@ -1856,7 +1854,7 @@ impl Stream {
self.recv.trace_id = trace_id.to_string();
}

/// Return true if the stream has data to be read.
/// Return true if the stream has data to be read or an error to be collected.
pub fn is_readable(&self) -> bool {
self.recv.ready()
}
Expand Down Expand Up @@ -2221,7 +2219,8 @@ impl RecvBuf {
Ok((len, self.is_fin()))
}

/// Return true if the stream has buffered data waiting to be read by application.
/// Return true if the stream has buffered data to be read or an error to
/// be collected.
fn ready(&self) -> bool {
match self.data.first_key_value() {
Some((_, buf)) => buf.off() == self.read_off,
Expand All @@ -2230,6 +2229,10 @@ impl RecvBuf {
}

/// Receive RESET_STREAM frame from peer, reset the stream at the given offset.
///
/// If the recv side is not shutdown by the application, an empty buffer with
/// FIN will be written to the recv buffer to notify the application that it
/// has been reset by its peer.
pub fn reset(&mut self, error_code: u64, final_size: u64) -> Result<usize> {
// Once a final size for a stream is known, it cannot change. If a RESET_STREAM
// frame is received indicating a change in the final size for the stream,
Expand Down Expand Up @@ -2271,8 +2274,9 @@ impl RecvBuf {
Ok(max_rx_off_delta as usize)
}

/// Shutdown the stream's receive-side, all subsequent data received on the stream
/// will be discarded.
/// Shutdown the stream's receive-side.
///
/// After this operation, any subsequent data received on the stream will be discarded.
fn shutdown(&mut self) -> Result<u64> {
if self.shutdown {
return Err(Error::Done);
Expand Down

0 comments on commit 4046a48

Please sign in to comment.