methodTstCustomSSHClient.Close
procedure Close;
Tears the connection down: sends SSH_MSG_DISCONNECT if the connection is still up, closes the socket and stops/frees the channel Broker thread. Works at any stage - after ConnectToHost alone, after a ConnectToHost or Login that failed, or after a Login. Called automatically on Destroy; an app calls it to disconnect explicitly. Safe to call when not connected. Another thread may call it while ConnectToHost, Login or RequestService runs - for a Cancel button, say, or through TsnipClient.Stop. That call uses the connection without the transport's lock, so Close then leaves the connection alone: it cancels the call and returns at once, and the call's own thread sends SSH_MSG_DISCONNECT reason 11, closes the connection and raises (see ConnectToHost, also for a Close while the TCP connection is being made, which on Windows the call waits out). Connected stays True until that call has ended. A Close made inside an event handler of the call, such as OnSetKey or OnGetClientPassword, cancels it the same way. Close does not stop a call that begins after it: a Close before ConnectToHost has made its transport - also in the moment just after ConnectToHost was called - finds no connection, and ConnectToHost then connects; a Close between two calls closes the connection itself, and the next call finds none. Not covered: a Close while CreateChannel, GlobalRequest or AddListener runs on another thread, which use the Broker that Close stops and frees. Freeing the client while one of those calls runs on another thread is not supported: Close it, and let the call return, first.