mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-15 08:30:02 +00:00
xous: add take_message() and send() calls to the envelope
Add a function to enable "regifting" a message that was sent to you. Signed-off-by: Sean Cross <sean@xobs.io>
This commit is contained in:
parent
04e91b8c44
commit
d8a413b7c2
1 changed files with 37 additions and 0 deletions
|
|
@ -1,4 +1,5 @@
|
|||
use super::{Message, MessageSender};
|
||||
use crate::CID;
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Debug, PartialEq)]
|
||||
|
|
@ -26,6 +27,42 @@ impl Envelope {
|
|||
ret.1[4],
|
||||
]
|
||||
}
|
||||
|
||||
pub fn take_message(self) -> Message {
|
||||
use core::mem::ManuallyDrop;
|
||||
// Convert `Self` into something that won't have its "Drop" method called
|
||||
let manual_self = ManuallyDrop::new(self);
|
||||
|
||||
// This function only works on memory messages
|
||||
unsafe { core::ptr::read(&manual_self.body) }
|
||||
}
|
||||
|
||||
pub fn send(self, connection: CID) -> Result<crate::Result, (Envelope, crate::Error)> {
|
||||
use core::mem::ManuallyDrop;
|
||||
// Convert `Self` into something that won't have its "Drop" method called
|
||||
let manual_self = ManuallyDrop::new(self);
|
||||
|
||||
// This function only works on memory messages
|
||||
let body = unsafe { core::ptr::read(&manual_self.body) };
|
||||
match body {
|
||||
Message::Move(_) => {
|
||||
let result = crate::send_message(connection, body);
|
||||
if let Ok(crate::Result::Ok) = result {
|
||||
return Ok(crate::Result::Ok);
|
||||
}
|
||||
return Err((
|
||||
ManuallyDrop::into_inner(manual_self),
|
||||
crate::Error::MemoryInUse,
|
||||
));
|
||||
}
|
||||
_ => {
|
||||
return Err((
|
||||
ManuallyDrop::into_inner(manual_self),
|
||||
crate::Error::MemoryInUse,
|
||||
))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "forget-memory-messages"))]
|
||||
|
|
|
|||
Loading…
Reference in a new issue