///////////////////////////////////////////////////////
| 652 | |
| 653 | //////////////////////////////////////////////////////////// |
| 654 | Sftp::Result Sftp::disconnect(const TimeoutWithPredicate& timeout) |
| 655 | { |
| 656 | // Clear the cached home path |
| 657 | m_impl->cachedHomePath.clear(); |
| 658 | |
| 659 | // Shut down the SFTP session |
| 660 | if (m_impl->sftpSession) |
| 661 | { |
| 662 | auto* sftpSession = m_impl->sftpSession.release(); |
| 663 | const auto result = m_impl->waitForOperationComplete([&] { return libssh2_sftp_shutdown(sftpSession); }, timeout); |
| 664 | |
| 665 | if (result == LIBSSH2_ERROR_EAGAIN) |
| 666 | return Result(Result::Value::Timeout); |
| 667 | } |
| 668 | |
| 669 | // Disconnect the SSH session |
| 670 | if (m_impl->ssh2Session) |
| 671 | { |
| 672 | const auto result = m_impl->waitForOperationComplete( |
| 673 | [&] |
| 674 | { return libssh2_session_disconnect_ex(m_impl->ssh2Session.get(), SSH_DISCONNECT_BY_APPLICATION, "", ""); }, |
| 675 | timeout); |
| 676 | |
| 677 | if (result == LIBSSH2_ERROR_EAGAIN) |
| 678 | return Result(Result::Value::Timeout); |
| 679 | |
| 680 | // Continue with destroying the SSH session and disconnecting the socket even if an error occurred |
| 681 | } |
| 682 | |
| 683 | // Destroy the SSH session |
| 684 | m_impl->ssh2Session.reset(); |
| 685 | |
| 686 | // Disconnect the TCP connection |
| 687 | m_impl->selectorRecv.clear(); |
| 688 | m_impl->selectorSend.clear(); |
| 689 | m_impl->selectorEither.clear(); |
| 690 | m_impl->socket.disconnect(); |
| 691 | |
| 692 | return Result(Result::Value::Success); |
| 693 | } |
| 694 | |
| 695 | |
| 696 | //////////////////////////////////////////////////////////// |