send_stream.rs

Overview

This file implements the functionality for managing send streams in a network protocol context, specifically focusing on bidirectional or unidirectional streams within a QUIC-based transport layer. It provides an abstraction for opening, sending data on, finishing, aborting, and handling lifecycle events of streams that send data. The implementation integrates tightly with the underlying msquic library to handle asynchronous stream operations, state transitions, and event callbacks.

The primary structure exposed is SendStream, representing a sending stream associated with a QUIC connection. Internally, it manages state using StreamInstance and StreamInner types, which coordinate sending buffers, track stream states, and invoke callbacks on various stream events.


Main Entities and Their Responsibilities

SendStream

Usage Example:

let mut send_stream = SendStream::open(&connection)?;
futures::executor::block_on(send_stream.send(vec![1, 2, 3]))?;
send_stream.poll_finish(&mut cx)?;

StreamInstance


StreamInner


StreamInnerExclusive


StreamInnerShared


Enums: Stream States

These states track the lifecycle of the stream and its sending capabilities.


SendData<'a>


WriteError


Buffer


Implementation Details and Algorithms


Interaction with Other System Components


Visual Diagram: Structure of send_stream.rs

classDiagram
class SendStream {
+open()
+debug_id()
+poll_start()
+id()
+poll_finish()
+poll_abort()
+abort()
+send()
}
class StreamInstance {
+id()
+check_sending()
+poll_send_data()
+send()
+poll_finish_write()
+poll_abort()
+abort()
}
class StreamInner {
+new()
+handle_event_start_complete()
+handle_event_send_complete()
+handle_event_peer_receive_aborted()
+handle_event_send_shutdown_complete()
+handle_event_shutdown_complete()
+handle_event_ideal_send_buffer_size()
+handle_event_peer_accepted()
+callback_handler_impl()
}
class StreamInnerExclusive {
-state
-start_status
-send_state
-sending_queue
-sending_seq_no
-next_seq_no
-send_error_code
-conn_error
-start_waiters
-send_waiters
-write_shutdown_waiters
}
class StreamInnerShared {
-id
}
class SendData {
+poll()
}
class Buffer {
+new()
+from_raw()
+into_raw()
+get_buffers()
}
class WriteError
SendStream --> StreamInstance : contains
StreamInstance --> StreamInner : contains
StreamInner --> StreamInnerExclusive : contains (Mutex)
StreamInner --> StreamInnerShared : contains
StreamInstance ..> SendData : returns Future
StreamInstance ..> WriteError : returns on errors
StreamInstance ..> Buffer : manages

Summary of Key Concepts Referenced