xous-names: implement non-blocking TryConnect call

This call can be used by clients to try connecting to a service. If the
service is not available, this will fail to connect.

Signed-off-by: Sean Cross <sean@xobs.io>
This commit is contained in:
Sean Cross 2022-11-07 18:46:02 +08:00
parent 3ca57bcf8b
commit 3ca323f0bb

View file

@ -26,6 +26,9 @@ enum ConnectError {
/// The message was not a mutable memory message /// The message was not a mutable memory message
InvalidMessageType = 4, InvalidMessageType = 4,
/// The server does not currently exist, and a blocking request was made
ServerNotFound = 5,
} }
#[derive(PartialEq)] #[derive(PartialEq)]
@ -464,7 +467,7 @@ fn main() -> ! {
xous::return_scalar(msg.sender, 0).unwrap(); xous::return_scalar(msg.sender, 0).unwrap();
} }
}), }),
Some(api::Opcode::BlockingConnect) => { Some(api::Opcode::BlockingConnect) | Some(api::Opcode::TryConnect) => {
if !msg.body.is_blocking() { if !msg.body.is_blocking() {
continue; continue;
} }
@ -479,12 +482,16 @@ fn main() -> ! {
respond_connect_success(msg, cid, disc) respond_connect_success(msg, cid, disc)
} }
Ok(ConnectSuccess::Wait) => { Ok(ConnectSuccess::Wait) => {
if msg.body.id() == api::Opcode::TryConnect as usize {
respond_connect_error(msg, ConnectError::ServerNotFound);
} else {
// Push waiting connections here, which will prevent it from getting // Push waiting connections here, which will prevent it from getting
// dropped and responded to. // dropped and responded to.
waiting_connections.push(msg); waiting_connections.push(msg);
} }
} }
} }
}
Some(api::Opcode::Lookup) => { Some(api::Opcode::Lookup) => {
let mem = msg.body.memory_message_mut().unwrap(); let mem = msg.body.memory_message_mut().unwrap();
let mut buffer = unsafe { Buffer::from_memory_message_mut(mem) }; let mut buffer = unsafe { Buffer::from_memory_message_mut(mem) };