-
Notifications
You must be signed in to change notification settings - Fork 113
Add RawMessageProvider trait and expand SendError/ReceiveError variants #756
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -43,6 +43,7 @@ macro_rules! log_println { | |
| pub trait Provider: | ||
| RawMutexProvider | ||
| + IPInterfaceProvider | ||
| + RawMessageProvider | ||
| + TimeProvider | ||
| + PunchthroughProvider | ||
| + DebugLogProvider | ||
|
|
@@ -382,17 +383,54 @@ pub trait IPInterfaceProvider { | |
| fn receive_ip_packet(&self, packet: &mut [u8]) -> Result<usize, ReceiveError>; | ||
| } | ||
|
|
||
| /// A non-exhaustive list of errors that can be thrown by [`IPInterfaceProvider::send_ip_packet`]. | ||
| /// Errors from send operations on [`IPInterfaceProvider`] and [`RawMessageProvider`]. | ||
| #[derive(Error, Debug)] | ||
| #[non_exhaustive] | ||
| pub enum SendError {} | ||
| pub enum SendError { | ||
| /// The underlying device returned an I/O error. The packet was not sent. | ||
| #[error("I/O error on send: errno {0}")] | ||
| Io(i32), | ||
| /// The channel is not available on this platform. | ||
| #[error("send channel unavailable")] | ||
| Unavailable, | ||
| } | ||
|
|
||
| /// A non-exhaustive list of errors that can be thrown by [`IPInterfaceProvider::receive_ip_packet`]. | ||
| /// Errors from receive operations on [`IPInterfaceProvider`] and [`RawMessageProvider`]. | ||
| #[derive(Error, Debug)] | ||
| #[non_exhaustive] | ||
| pub enum ReceiveError { | ||
| #[error("Receive operation would block")] | ||
| WouldBlock, | ||
| #[error("IPC protocol error: oversized frame")] | ||
| ProtocolError, | ||
| #[error("Channel closed (EOF)")] | ||
| Eof, | ||
| } | ||
|
|
||
| /// A raw byte-stream channel for direct message passing between the guest and | ||
| /// the host (bypassing the IP network stack). | ||
| /// | ||
| /// When available, this provides a fast path for protocols like 9P that would | ||
| /// otherwise pay the overhead of traversing two smoltcp stacks. | ||
|
Comment on lines
+413
to
+414
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: "network stacks" not "smoltcp stacks". Doc strings should not promise unnecessary internal details. |
||
| /// | ||
| /// The default implementation returns [`ReceiveError::WouldBlock`] / | ||
| /// [`SendError::Unavailable`], indicating the channel is not available. | ||
|
Comment on lines
+416
to
+417
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think the default should be |
||
| /// Platforms that support direct messaging override these methods. | ||
| pub trait RawMessageProvider { | ||
| /// Send bytes to the host over the raw channel. | ||
| /// | ||
| /// Returns `Ok(n)` with the number of bytes sent, or an error. | ||
| fn send_raw_message(&self, _data: &[u8]) -> Result<usize, SendError> { | ||
| Err(SendError::Unavailable) | ||
| } | ||
|
|
||
| /// Receive bytes from the host over the raw channel. | ||
| /// | ||
| /// Returns `Ok(n)` with the number of bytes read into `buf`, or | ||
| /// [`ReceiveError::WouldBlock`] if no data is available yet. | ||
| fn recv_raw_message(&self, _buf: &mut [u8]) -> Result<usize, ReceiveError> { | ||
| Err(ReceiveError::WouldBlock) | ||
| } | ||
| } | ||
|
|
||
| /// An interface to understanding time. | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As mentioned on #743, hardcoding an i32 here is wrong; pick actually relevant errors