From 3ca57bcf8bf33e41f5343a439cce2e336adff85a Mon Sep 17 00:00:00 2001 From: Sean Cross Date: Mon, 7 Nov 2022 18:45:25 +0800 Subject: [PATCH 1/2] xous-api-names: add TryConnect This is a non-blocking version of Connect that is fallible. Signed-off-by: Sean Cross --- api/xous-api-names/src/api.rs | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/api/xous-api-names/src/api.rs b/api/xous-api-names/src/api.rs index f93e7e0b4..b16c093f7 100644 --- a/api/xous-api-names/src/api.rs +++ b/api/xous-api-names/src/api.rs @@ -52,6 +52,34 @@ pub enum Opcode { /// } /// ``` BlockingConnect = 6, + + /// Connect to a Server, returning the connection ID or an authentication request if + /// it exists, and returning ServerNotFound if it does not exist. + /// + /// # Message Types + /// + /// * MutableLend + /// + /// # Arguments + /// + /// The memory being pointed to should be a &str, and the length of the string should + /// be specified in the `valid` field. + /// + /// # Return Values + /// + /// Memory is overwritten to contain a return value. This return value can be defined + /// as the following enum: + /// + /// ```rust + /// #[repr(C)] + /// #[non_exhaustive] + /// enum ConnectResult { + /// Success(xous::CID /* connection ID */, [u32; 4] /* Disconnection token */), + /// Error(u32 /* error code */), + /// Unhandled, /* Catchall for future Results */ + /// } + /// ``` + TryConnect = 7, } #[derive(Debug, rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)] From 3ca323f0bb11388d432183cb87caa03c4342064e Mon Sep 17 00:00:00 2001 From: Sean Cross Date: Mon, 7 Nov 2022 18:46:02 +0800 Subject: [PATCH 2/2] 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 --- services/xous-names/src/main.rs | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/services/xous-names/src/main.rs b/services/xous-names/src/main.rs index 892b18098..25b2824a5 100644 --- a/services/xous-names/src/main.rs +++ b/services/xous-names/src/main.rs @@ -26,6 +26,9 @@ enum ConnectError { /// The message was not a mutable memory message InvalidMessageType = 4, + + /// The server does not currently exist, and a blocking request was made + ServerNotFound = 5, } #[derive(PartialEq)] @@ -464,7 +467,7 @@ fn main() -> ! { xous::return_scalar(msg.sender, 0).unwrap(); } }), - Some(api::Opcode::BlockingConnect) => { + Some(api::Opcode::BlockingConnect) | Some(api::Opcode::TryConnect) => { if !msg.body.is_blocking() { continue; } @@ -479,9 +482,13 @@ fn main() -> ! { respond_connect_success(msg, cid, disc) } Ok(ConnectSuccess::Wait) => { - // Push waiting connections here, which will prevent it from getting - // dropped and responded to. - waiting_connections.push(msg); + 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 + // dropped and responded to. + waiting_connections.push(msg); + } } } }