Ver código fonte

Bug fix: Canceled or failed FTP transfer caused connection loss

Caused by Bug 1878.

Source commit: 6931ec7e394231cc73e92b4fd765fd7c08a667ee
Martin Prikryl 4 anos atrás
pai
commit
53e82dadbe

+ 8 - 3
source/filezilla/FtpControlSocket.cpp

@@ -2585,7 +2585,7 @@ void CFtpControlSocket::OnClose(int nErrorCode)
     DoClose();
 }
 
-void CFtpControlSocket::ResetTransferSocket(bool Error)
+void CFtpControlSocket::ResetTransferSocket(int Error)
 {
   if (Error)
   {
@@ -2595,9 +2595,14 @@ void CFtpControlSocket::ResetTransferSocket(bool Error)
   {
     LogMessage(FZ_LOG_INFO, L"Destroying data socket after transfer completed");
   }
+  bool Close =
+    (Error != 0) &&
+    DebugAlwaysTrue(m_pTransferSocket != NULL) &&
+    (m_pTransferSocket->m_uploaded > 0) &&
+    FLAGCLEAR(Error, FZ_REPLY_CANCEL);
   delete m_pTransferSocket;
   m_pTransferSocket = NULL;
-  if (Error)
+  if (Close)
   {
     // close the control connection too to allow reconnect => transfer resume
     LogMessage(FZ_LOG_WARNING, L"Transfer connection failed, closing");
@@ -4554,7 +4559,7 @@ void CFtpControlSocket::ResetOperation(int nSuccessful /*=FALSE*/)
 
   if (m_pTransferSocket)
   {
-    ResetTransferSocket(nSuccessful & FZ_REPLY_ERROR);
+    ResetTransferSocket(nSuccessful & (FZ_REPLY_ERROR | FZ_REPLY_CANCEL));
   }
 
   if (m_pDataFile)

+ 1 - 1
source/filezilla/FtpControlSocket.h

@@ -117,7 +117,7 @@ protected:
   void SetFileExistsAction(int nAction, COverwriteRequestData * pData);
   void SetVerifyCertResult(int nResult, t_SslCertData * pData);
   void ResetOperation(int nSuccessful = -1);
-  void ResetTransferSocket(bool Error);
+  void ResetTransferSocket(int Error);
 
   void DoClose(int nError = 0);
   int GetReplyCode();

+ 3 - 0
source/filezilla/TransferSocket.cpp

@@ -35,6 +35,7 @@ CTransferSocket::CTransferSocket(CFtpControlSocket *pOwner, int nMode)
   m_nInternalMessageID = 0;
   m_transferdata.transfersize = 0;
   m_transferdata.transferleft = 0;
+  m_uploaded = 0;
   m_nNotifyWaiting = 0;
   m_bActivationPending = false;
   m_LastSendBufferUpdate = 0;
@@ -665,6 +666,7 @@ void CTransferSocket::OnSend(int nErrorCode)
         return;
       }
 
+      m_uploaded += numsent;
       m_pOwner->SpeedLimitAddTransferredBytes(CFtpControlSocket::upload, numsent);
       m_LastActiveTime = CTime::GetCurrentTime();
 
@@ -748,6 +750,7 @@ void CTransferSocket::OnSend(int nErrorCode)
         m_pOwner->SpeedLimitAddTransferredBytes(CFtpControlSocket::upload, numsent);
         m_LastActiveTime = CTime::GetCurrentTime();
         m_transferdata.transferleft -= numsent;
+        m_uploaded += numsent;
       }
 
       if (numsent==SOCKET_ERROR || !numsent)

+ 1 - 0
source/filezilla/TransferSocket.h

@@ -34,6 +34,7 @@ public:
   BOOL m_bListening;
   CFile * m_pFile;
   t_transferdata m_transferdata;
+  __int64 m_uploaded;
   void SetActive();
   int CheckForTimeout(int delay);
 #ifndef MPEXT_NO_GSS