Pārlūkot izejas kodu

Switch an error code on the network.

Jing Yang 5 gadi atpakaļ
vecāks
revīzija
c77c3d4251
2 mainītis faili ar 9 papildinājumiem un 6 dzēšanām
  1. 7 4
      src/client.rs
  2. 2 2
      src/network.rs

+ 7 - 4
src/client.rs

@@ -15,14 +15,17 @@ pub struct Client {
 
 impl Client {
     /// Error type and meaning
-    /// * Connection aborted: The client did not have a chance to send the
-    /// request, or will not receive a reply because the network is down.
-    /// * Not connected: The network does not allow the client to send requests.
+    /// * Not connected: The client did not have a chance to send the request
+    /// because the network is down.
+    /// * Permission denied: The network does not allow the client to send
+    /// requests.
     /// * Broken pipe: The network no longer allows the client to send requests.
     /// * Not found: The network could not find the target server.
     /// * Invalid input: The server could not find the service / method to call.
     /// * Connection reset: The server received the request, but decided to stop
     /// responding.
+    /// * Connection aborted: The client will not receive a reply because the
+    /// the connection is closed by the network.
     pub async fn call_rpc(
         &self,
         service_method: String,
@@ -40,7 +43,7 @@ impl Client {
         self.request_bus.send(rpc).map_err(|e| {
             // The receiving end has been closed. Network connection is broken.
             std::io::Error::new(
-                std::io::ErrorKind::ConnectionAborted,
+                std::io::ErrorKind::NotConnected,
                 format!(
                     "Cannot send rpc, client {} is disconnected. {}",
                     self.client.clone(),

+ 2 - 2
src/network.rs

@@ -87,7 +87,7 @@ impl Network {
         let (enabled, server_name) =
             self.clients.get(client).ok_or_else(|| {
                 std::io::Error::new(
-                    std::io::ErrorKind::NotConnected,
+                    std::io::ErrorKind::PermissionDenied,
                     format!("Client {} is not connected.", client),
                 )
             })?;
@@ -446,7 +446,7 @@ mod tests {
         let (rpc, rx) = make_aborting_rpc(NON_CLIENT, TEST_SERVER);
         let reply = send_rpc(rpc, rx, TEST_CLIENT, TEST_SERVER, true);
         let err = reply.expect_err("Network should check client names");
-        assert_eq!(std::io::ErrorKind::NotConnected, err.kind());
+        assert_eq!(std::io::ErrorKind::PermissionDenied, err.kind());
 
         Ok(())
     }