| ... | @@ -77,7 +77,7 @@ impl Client { | ... | @@ -77,7 +77,7 @@ impl Client { |
| 77 | let mut connection = sign_in(address, &credentials, timeout).await?; | 77 | let mut connection = sign_in(address, &credentials, timeout).await?; |
| 78 | let tree = Tree::connect(&mut connection, share) | 78 | let tree = Tree::connect(&mut connection, share) |
| 79 | .await | 79 | .await |
| 80 | .map_err(io::Error::other)?; | 80 | .map_err(io_error)?; |
| 81 | Ok::<_, io::Error>((connection, tree)) | 81 | Ok::<_, io::Error>((connection, tree)) |
| 82 | }) | 82 | }) |
| 83 | .await | 83 | .await |
| ... | @@ -150,7 +150,7 @@ impl Client { | ... | @@ -150,7 +150,7 @@ impl Client { |
| 150 | }; | 150 | }; |
| 151 | let frame = frame | 151 | let frame = frame |
| 152 | .map_err(|_| io::Error::from(io::ErrorKind::TimedOut)) | 152 | .map_err(|_| io::Error::from(io::ErrorKind::TimedOut)) |
| 153 | .and_then(|result| result.map_err(io::Error::other)) | 153 | .and_then(|result| result.map_err(io_error)) |
| 154 | .inspect_err(|_| self.retire())?; | 154 | .inspect_err(|_| self.retire())?; |
| 155 | self.unpack(&self.body(command, frame)?) | 155 | self.unpack(&self.body(command, frame)?) |
| 156 | } | 156 | } |
| ... | @@ -184,15 +184,13 @@ impl Client { | ... | @@ -184,15 +184,13 @@ impl Client { |
| 184 | }; | 184 | }; |
| 185 | let frames = frames | 185 | let frames = frames |
| 186 | .map_err(|_| io::Error::from(io::ErrorKind::TimedOut)) | 186 | .map_err(|_| io::Error::from(io::ErrorKind::TimedOut)) |
| 187 | .and_then(|result| result.map_err(io::Error::other)) | 187 | .and_then(|result| result.map_err(io_error)) |
| 188 | .inspect_err(|_| self.retire())?; | 188 | .inspect_err(|_| self.retire())?; |
| 189 | Ok(frames | 189 | Ok(frames |
| 190 | .into_iter() | 190 | .into_iter() |
| 191 | .zip(requests) | 191 | .zip(requests) |
| 192 | .map(|(frame, (command, _))| { | 192 | .map(|(frame, (command, _))| { |
| 193 | let frame = frame | 193 | let frame = frame.map_err(io_error).inspect_err(|_| self.retire())?; |
| 194 | .map_err(io::Error::other) | | |
| 195 | .inspect_err(|_| self.retire())?; | | |
| 196 | self.body(*command, frame) | 194 | self.body(*command, frame) |
| 197 | }) | 195 | }) |
| 198 | .collect()) | 196 | .collect()) |
| ... | @@ -568,7 +566,7 @@ pub fn shares( | ... | @@ -568,7 +566,7 @@ pub fn shares( |
| 568 | let mut connection = sign_in(address, &credentials, timeout).await?; | 566 | let mut connection = sign_in(address, &credentials, timeout).await?; |
| 569 | let shares = smb2::client::list_shares(&mut connection) | 567 | let shares = smb2::client::list_shares(&mut connection) |
| 570 | .await | 568 | .await |
| 571 | .map_err(io::Error::other); | 569 | .map_err(io_error); |
| 572 | connection.mark_dead(); | 570 | connection.mark_dead(); |
| 573 | shares | 571 | shares |
| 574 | }) | 572 | }) |
| ... | @@ -578,6 +576,20 @@ pub fn shares( | ... | @@ -578,6 +576,20 @@ pub fn shares( |
| 578 | Ok(shares.into_iter().map(|share| share.name).collect()) | 576 | Ok(shares.into_iter().map(|share| share.name).collect()) |
| 579 | } | 577 | } |
| 580 | | 578 | |
| | 579 | /// `error` inside an `io::Error` whose kind says whether the server was reached: a lost or |
| | 580 | /// unanswered connection is `NotConnected` or `TimedOut`, and a socket's failure keeps its kind. |
| | 581 | fn io_error(error: smb2::Error) -> io::Error { |
| | 582 | let kind = match &error { |
| | 583 | smb2::Error::Io(source) => source.kind(), |
| | 584 | error => match error.kind() { |
| | 585 | smb2::ErrorKind::ConnectionLost => io::ErrorKind::NotConnected, |
| | 586 | smb2::ErrorKind::TimedOut => io::ErrorKind::TimedOut, |
| | 587 | _ => io::ErrorKind::Other, |
| | 588 | }, |
| | 589 | }; |
| | 590 | io::Error::new(kind, error) |
| | 591 | } |
| | 592 | |
| 581 | /// A negotiated session with the server at `address`, signed in with `credentials`. | 593 | /// A negotiated session with the server at `address`, signed in with `credentials`. |
| 582 | async fn sign_in( | 594 | async fn sign_in( |
| 583 | address: &str, | 595 | address: &str, |
| ... | @@ -586,14 +598,14 @@ async fn sign_in( | ... | @@ -586,14 +598,14 @@ async fn sign_in( |
| 586 | ) -> io::Result<Connection> { | 598 | ) -> io::Result<Connection> { |
| 587 | let mut connection = Connection::connect(address, timeout) | 599 | let mut connection = Connection::connect(address, timeout) |
| 588 | .await | 600 | .await |
| 589 | .map_err(io::Error::other)?; | 601 | .map_err(io_error)?; |
| 590 | connection.set_compression_requested(false); | 602 | connection.set_compression_requested(false); |
| 591 | if let Err(error) = connection.negotiate().await { | 603 | if let Err(error) = connection.negotiate().await { |
| 592 | connection.mark_dead(); | 604 | connection.mark_dead(); |
| 593 | return Err(if speaks_only_smb1(address, timeout).await { | 605 | return Err(if speaks_only_smb1(address, timeout).await { |
| 594 | io::Error::new(io::ErrorKind::Unsupported, Refusal::Smb1) | 606 | io::Error::new(io::ErrorKind::Unsupported, Refusal::Smb1) |
| 595 | } else { | 607 | } else { |
| 596 | io::Error::other(error) | 608 | io_error(error) |
| 597 | }); | 609 | }); |
| 598 | } | 610 | } |
| 599 | Session::setup( | 611 | Session::setup( |
| ... | @@ -603,7 +615,7 @@ async fn sign_in( | ... | @@ -603,7 +615,7 @@ async fn sign_in( |
| 603 | credentials.domain, | 615 | credentials.domain, |
| 604 | ) | 616 | ) |
| 605 | .await | 617 | .await |
| 606 | .map_err(io::Error::other)?; | 618 | .map_err(io_error)?; |
| 607 | Ok(connection) | 619 | Ok(connection) |
| 608 | } | 620 | } |
| 609 | | 621 | |