浏览代码

Timeout* counters

(cherry picked from commit 85f0e92ca63dd23fbd71f2172c27aa9fe39042b9)

# Conflicts:
#	source/core/SftpFileSystem.cpp

Source commit: a9edfadbee1ef7ccc147800b9bf786e59ea2cb59
Martin Prikryl 1 年之前
父节点
当前提交
d29a968ac7
共有 4 个文件被更改,包括 31 次插入4 次删除
  1. 6 0
      source/core/ScpFileSystem.cpp
  2. 18 3
      source/core/SecureShell.cpp
  3. 3 1
      source/core/SecureShell.h
  4. 4 0
      source/core/SftpFileSystem.cpp

+ 6 - 0
source/core/ScpFileSystem.cpp

@@ -1967,6 +1967,9 @@ void __fastcall TSCPFileSystem::SCPSource(const UnicodeString FileName,
 
     try
     {
+      TValueRestorer<TSecureShellMode> SecureShellModeRestorer(FSecureShell->Mode);
+      FSecureShell->Mode = ssmUploading;
+
       // During ASCII transfer we will load whole file to this buffer
       // than convert EOL and send it at once, because before converting EOL
       // we can't know its size
@@ -2460,6 +2463,9 @@ void __fastcall TSCPFileSystem::SCPSink(const UnicodeString TargetDir,
 
   FileData.SetTime = 0;
 
+  TValueRestorer<TSecureShellMode> SecureShellModeRestorer(FSecureShell->Mode);
+  FSecureShell->Mode = ssmDownloading;
+
   FSecureShell->SendNull();
 
   while (!OperationProgress->Cancel)

+ 18 - 3
source/core/SecureShell.cpp

@@ -79,6 +79,7 @@ __fastcall TSecureShell::TSecureShell(TSessionUI* UI,
   FCallbackSet = new callback_set();
   memset(FCallbackSet, 0, sizeof(*FCallbackSet));
   FCallbackSet->ready_event = INVALID_HANDLE_VALUE;
+  Mode = ssmNone;
 }
 //---------------------------------------------------------------------------
 __fastcall TSecureShell::~TSecureShell()
@@ -1309,8 +1310,22 @@ void __fastcall TSecureShell::SendBuffer(unsigned int & Result)
   }
 }
 //---------------------------------------------------------------------------
-void TSecureShell::TimeoutAbort(unsigned int Answer)
+void TSecureShell::TimeoutAbort(unsigned int Answer, bool Sending)
 {
+  UnicodeString CounterName;
+  if (Mode == ssmUploading)
+  {
+    CounterName = Sending ? L"TimeoutUploadingSending" : L"TimeoutUploadingReceiving";
+  }
+  else if (Mode == ssmDownloading)
+  {
+    CounterName = Sending ? L"TimeoutDownloadingSending" : L"TimeoutDownloadingReceiving";
+  }
+  if (!CounterName.IsEmpty())
+  {
+    Configuration->Usage->Inc(CounterName);
+  }
+
   FatalError(MainInstructions(LoadStr(Answer == qaAbort ? USER_TERMINATED : TIMEOUT_ERROR)));
 }
 //---------------------------------------------------------------------------
@@ -1353,7 +1368,7 @@ void __fastcall TSecureShell::DispatchSendBuffer(int BufSize)
 
         case qaAbort:
         case qaNo:
-          TimeoutAbort(Answer);
+          TimeoutAbort(Answer, true);
           break;
       }
     }
@@ -1937,7 +1952,7 @@ void __fastcall TSecureShell::WaitForData()
 
         case qaAbort:
         case qaNo:
-          TimeoutAbort(Answer);
+          TimeoutAbort(Answer, false);
           break;
       }
     }

+ 3 - 1
source/core/SecureShell.h

@@ -23,6 +23,7 @@ enum TSshImplementation { sshiUnknown, sshiOpenSSH, sshiProFTPD, sshiBitvise, ss
 struct ScpLogPolicy;
 struct LogContext;
 struct ScpSeat;
+enum TSecureShellMode { ssmNone, ssmUploading, ssmDownloading };
 //---------------------------------------------------------------------------
 class TSecureShell
 {
@@ -101,7 +102,7 @@ private:
   void __fastcall DispatchSendBuffer(int BufSize);
   void __fastcall SendBuffer(unsigned int & Result);
   unsigned int __fastcall TimeoutPrompt(TQueryParamsTimerEvent PoolEvent);
-  void TimeoutAbort(unsigned int Answer);
+  void TimeoutAbort(unsigned int Answer, bool Sending);
   bool __fastcall TryFtp();
   UnicodeString __fastcall ConvertInput(const RawByteString & Input);
   void __fastcall GetRealHost(UnicodeString & Host, int & Port);
@@ -190,6 +191,7 @@ public:
   __property bool Simple = { read = FSimple, write = FSimple };
   __property TSshImplementation SshImplementation = { read = FSshImplementation };
   __property bool UtfStrings = { read = FUtfStrings, write = FUtfStrings };
+  TSecureShellMode Mode;
 };
 //---------------------------------------------------------------------------
 #endif

+ 4 - 0
source/core/SftpFileSystem.cpp

@@ -4804,6 +4804,8 @@ void __fastcall TSFTPFileSystem::Source(
 
     TEncryption Encryption(FTerminal->GetEncryptKey());
     bool Encrypt = FTerminal->IsFileEncrypted(DestFullName, CopyParam->EncryptNewFiles);
+    TValueRestorer<TSecureShellMode> SecureShellModeRestorer(FSecureShell->Mode);
+    FSecureShell->Mode = ssmUploading;
     TSFTPUploadQueue Queue(this, (Encrypt ? &Encryption : NULL));
     try
     {
@@ -5550,6 +5552,8 @@ void __fastcall TSFTPFileSystem::Sink(
 
     // at end of this block queue is discarded
     {
+      TValueRestorer<TSecureShellMode> SecureShellModeRestorer(FSecureShell->Mode);
+      FSecureShell->Mode = ssmDownloading;
       TSFTPDownloadQueue Queue(this);
       try
       {