DataFlex
DataFlex
Abort a Running SSH Tunnel Operation
See more SSH Tunnel Examples
Demonstrates the AbortCurrent property, which requests that the currently running foreground operation be aborted. It is intended to be set to true from another thread — for example, to interrupt a synchronous Connect that is waiting for an unresponsive server.
Background: A synchronous call like
Connect blocks the calling thread until it finishes or times out, which is a problem when a user clicks "Cancel" or the app needs to shut down. Setting AbortCurrent from a different thread breaks the blocked operation out early, returning a failure the caller can handle. Note its scope is deliberately limited to the current foreground operation: it does not stop the background listener or terminate established tunnel clients — use StopAccepting or CloseTunnel for those.Chilkat DataFlex Downloads
Use ChilkatAx-win32.pkg
Procedure Test
Boolean iSuccess
Handle hoTunnel
Integer iSshPort
Boolean iWaitForThreadExit
String sTemp1
Move False To iSuccess
// Demonstrates the SshTunnel.AbortCurrent property, which requests that the currently running
// foreground operation be aborted.
Get Create (RefClass(cComChilkatSshTunnel)) To hoTunnel
If (Not(IsComObjectCreated(hoTunnel))) Begin
Send CreateComObject of hoTunnel
End
// AbortCurrent is intended to be set to True from ANOTHER thread to interrupt a synchronous
// operation in progress -- for example, a Connect that is waiting for an unresponsive server.
// It does not stop the background listener or terminate established background tunnel clients.
//
// The assignment below illustrates the property. In a real application it would be set on a
// separate thread while Connect blocks; if it becomes True, the blocked Connect returns with a
// failure.
Set ComAbortCurrent Of hoTunnel To False
Set ComDestHostname Of hoTunnel To "db.internal.example.com"
Set ComDestPort Of hoTunnel To 5432
Move 22 To iSshPort
Get ComConnect Of hoTunnel "ssh.example.com" iSshPort To iSuccess
If (iSuccess = False) Begin
Get ComLastErrorText Of hoTunnel To sTemp1
Showln sTemp1
Procedure_Return
End
Showln "Connected."
Move True To iWaitForThreadExit
Get ComCloseTunnel Of hoTunnel iWaitForThreadExit To iSuccess
If (iSuccess = False) Begin
Get ComLastErrorText Of hoTunnel To sTemp1
Showln sTemp1
Procedure_Return
End
End_Procedure