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