-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
+ libssh2_session_get_timeout + libssh2_session_set_timeout + property KeepAliveTimeOut
- Loading branch information
Showing
2 changed files
with
63 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
{ uMySFTPClient.pas } // version: 2020.1114.2017 | ||
{ uMySFTPClient.pas } // version: 2023.1211.1600 | ||
{ ** | ||
* Copyright (c) 2010, Zeljko Marjanovic <[email protected]> | ||
* This code is licensed under MPL 1.1 | ||
|
@@ -202,7 +202,8 @@ TSSH2Client = class(TComponent) | |
FLastErrStr: string; | ||
FBlockingMode: Boolean; | ||
FKeepAlive: Boolean; | ||
FTimeOut: Integer; // keepalive timeout interval in seconds | ||
FKeepAliveTimeOut: Integer; // keepalive timeout interval in seconds | ||
FTimeOut: Integer; // socket timeout interval in seconds | ||
FSockBufLen: Integer; | ||
FHashMgr: IHashManager; | ||
FSocket: Integer; | ||
|
@@ -221,6 +222,7 @@ TSSH2Client = class(TComponent) | |
function GetLibString: string; | ||
procedure SetBlockingMode(Value: Boolean); | ||
procedure SetKeepAlive(Value: Boolean); | ||
procedure SetKeepAliveTimeOut(Value: Integer); | ||
procedure SetTimeOut(Value: Integer); | ||
protected | ||
function GetSessionPtr: PLIBSSH2_SESSION; | ||
|
@@ -251,6 +253,7 @@ TSSH2Client = class(TComponent) | |
property IPVersion: TIPVersion read FIPVersion write FIPVersion; | ||
property BlockingMode: Boolean read FBlockingMode write SetBlockingMode default True; | ||
property KeepAlive: Boolean read FKeepAlive write SetKeepAlive; | ||
property KeepAliveTimeOut: Integer read FKeepAliveTimeOut write SetKeepAliveTimeOut; | ||
property TimeOut: Integer read FTimeOut write SetTimeOut; | ||
property SockSndRcvBufLen: Integer read FSockBufLen write FSockBufLen; | ||
property AuthModes: TAuthModes read FAuthModes write SetAuthModes default [amTryAll]; | ||
|
@@ -2160,7 +2163,8 @@ constructor TSSH2Client.Create(AOwner: TComponent); | |
//FCanceled := False; | ||
FBlockingMode := True; | ||
//FKeepAlive := False; | ||
FTimeOut := 10; | ||
FKeepAliveTimeOut := 10; | ||
FTimeOut := 90; | ||
FSockBufLen := 8 * 1024; | ||
FSocket := INVALID_SOCKET; | ||
FCodePage := CP_UTF8; | ||
|
@@ -2449,31 +2453,56 @@ procedure TSSH2Client.SetKeepAlive(Value: Boolean); | |
end; | ||
end; | ||
|
||
procedure TSSH2Client.SetTimeOut(Value: Integer); | ||
var | ||
KeepAliveTimeOut, R, i: Integer; | ||
procedure TSSH2Client.SetKeepAliveTimeOut(Value: Integer); | ||
var ATimeOut: Integer; //R, i: Integer; | ||
begin | ||
if Value < 0 then Value := 0; | ||
if (FTimeOut <> Value) or (Assigned(FSession) and not fConnected) then | ||
if Value < 0 then Value := 0; if (Value > 0) and (Value<10) then Value := 10; | ||
if (FKeepAliveTimeOut <> Value) or (Assigned(FSession) and not fConnected) then | ||
begin | ||
FTimeOut := Value; | ||
FKeepAliveTimeOut := Value; | ||
// | ||
if Assigned(FSession) then | ||
begin | ||
// send timeout | ||
KeepAliveTimeOut := FTimeOut; | ||
if (KeepAliveTimeOut > 0) and (KeepAliveTimeOut<10) then KeepAliveTimeOut := 10; | ||
if fDebugMode then dbg(strwhen('connect: ', fConnected)+'libssh2_keepalive_config: active: '+BoolToStr(FKeepAlive, True)+'; seconds: ' + IntToStr(KeepAliveTimeOut)); | ||
libssh2_keepalive_config(FSession, bool2int(FKeepAlive), KeepAliveTimeOut); // FTimeOut - number of seconds | ||
ATimeOut := FKeepAliveTimeOut; | ||
if fDebugMode then dbg(strwhen('connect: ', fConnected)+'libssh2_keepalive_config: active: '+BoolToStr(FKeepAlive, True)+'; seconds: ' + IntToStr(ATimeOut)); | ||
libssh2_keepalive_config(FSession, bool2int(FKeepAlive), ATimeOut); // FTimeOut - number of seconds | ||
// check/read keepalive timeout settings: | ||
i := 0; | ||
R := libssh2_keepalive_send(FSession, {seconds_to_next:}i); | ||
while (R = LIBSSH2_ERROR_EAGAIN) do begin | ||
waitsocket(); | ||
(* | ||
if not fBlockingMode then | ||
begin | ||
i := 0; //? i := bool2int( (not fBlockingMode) ); | ||
R := libssh2_keepalive_send(FSession, {seconds_to_next:}i); | ||
while (R = LIBSSH2_ERROR_EAGAIN) do begin | ||
waitsocket(); | ||
R := libssh2_keepalive_send(FSession, {seconds_to_next:}i); | ||
end; | ||
//if R < 0 then ; | ||
if fDebugMode then dbg(strwhen('connect: ', fConnected)+'libssh2_keepalive_config. OK: '+BoolToStr(i = KeepAliveTimeOut, True)); | ||
end; | ||
//if R < 0 then ; | ||
if fDebugMode then dbg(strwhen('connect: ', fConnected)+'libssh2_keepalive_config. OK: '+BoolToStr(i = KeepAliveTimeOut, True)); | ||
*) | ||
end; | ||
end; | ||
end; | ||
|
||
procedure TSSH2Client.SetTimeOut(Value: Integer); | ||
var ATimeOut: Integer; | ||
begin | ||
if Value < 0 then Value := 0; if (Value > 0) and (Value<10) then Value := 10; | ||
if (FTimeOut <> Value) or (Assigned(FSession) and not fConnected) then | ||
begin | ||
FTimeOut := Value; | ||
// | ||
if Assigned(FSession) then | ||
begin | ||
ATimeOut := FTimeOut; | ||
if fDebugMode then dbg(strwhen('connect: ', fConnected)+'libssh2_session_set_timeout: seconds: ' + IntToStr(ATimeOut)); | ||
libssh2_session_set_timeout(FSession, ATimeOut); | ||
|
||
ATimeOut := libssh2_session_get_timeout(FSession); | ||
if fDebugMode then dbg(strwhen('connect: ', fConnected)+'libssh2_session_get_timeout: seconds: ' + IntToStr(ATimeOut)); | ||
|
||
if FTimeOut <> ATimeOut then | ||
FTimeOut := ATimeOut; | ||
end; | ||
end; | ||
end; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters