Ticket #1519: filezilla3_rc1_keepalive2.patch
File filezilla3_rc1_keepalive2.patch, 11.4 KB (added by , 16 years ago) |
---|
-
src/engine/ControlSocket.h
diff -Nur Filezilla3/src/engine/ControlSocket.h Filezilla3.patch/src/engine/ControlSocket.h
old new 115 115 virtual int Chmod(const CChmodCommand& command) { return FZ_REPLY_NOTSUPPORTED; } 116 116 virtual bool Connected() const = 0; 117 117 118 virtual int KeepAlive(const CKeepAliveCommand& command) { return FZ_REPLY_OK; } 119 118 120 // If m_pCurrentOpData is zero, this function returns the current command 119 121 // from the engine. 120 122 enum Command GetCurrentCommandId() const; -
src/engine/FileZillaEngine.cpp
diff -Nur Filezilla3/src/engine/FileZillaEngine.cpp Filezilla3.patch/src/engine/FileZillaEngine.cpp
old new 70 70 case cmd_chmod: 71 71 res = Chmod(reinterpret_cast<const CChmodCommand&>(command)); 72 72 break; 73 case cmd_keepalive: 74 res = KeepAlive(reinterpret_cast<const CKeepAliveCommand &>(command)); 75 break; 73 76 default: 74 77 return FZ_REPLY_SYNTAXERROR; 75 78 } -
src/engine/commands.cpp
diff -Nur Filezilla3/src/engine/commands.cpp Filezilla3.patch/src/engine/commands.cpp
old new 10 10 return m_Server; 11 11 } 12 12 13 CKeepAliveCommand::CKeepAliveCommand(bool keepAlive /*=true*/) 14 : m_keepAlive(keepAlive) 15 { 16 } 17 18 bool CKeepAliveCommand::IsKeepAlive() const 19 { 20 return m_keepAlive; 21 } 22 13 23 CListCommand::CListCommand(bool refresh /*=false*/) 14 24 : m_refresh(refresh) 15 25 { -
src/engine/engineprivate.cpp
diff -Nur Filezilla3/src/engine/engineprivate.cpp Filezilla3.patch/src/engine/engineprivate.cpp
old new 525 525 return m_pControlSocket->Chmod(command); 526 526 } 527 527 528 int CFileZillaEnginePrivate::KeepAlive(const CKeepAliveCommand& command) 529 { 530 m_pCurrentCommand = command.Clone(); 531 return m_pControlSocket->KeepAlive(command); 532 } 533 528 534 void CFileZillaEnginePrivate::SendDirectoryListingNotification(const CServerPath& path, bool onList, bool modified, bool failed) 529 535 { 530 536 wxASSERT(m_pControlSocket); -
src/engine/ftpcontrolsocket.cpp
diff -Nur Filezilla3/src/engine/ftpcontrolsocket.cpp Filezilla3.patch/src/engine/ftpcontrolsocket.cpp
old new 24 24 #define LOGON_CUSTOMCOMMANDS 10 25 25 #define LOGON_DONE 11 26 26 27 #define KEEPALIVE_TIMER_ID wxID_HIGHEST + 5 28 27 29 BEGIN_EVENT_TABLE(CFtpControlSocket, CRealControlSocket) 28 30 EVT_FZ_EXTERNALIPRESOLVE(wxID_ANY, CFtpControlSocket::OnExternalIPAddress) 31 EVT_TIMER(wxID_ANY, CFtpControlSocket::OnTimer) 29 32 END_EVENT_TABLE(); 30 33 31 34 CRawTransferOpData::CRawTransferOpData() … … 137 140 m_pTlsSocket = 0; 138 141 m_protectDataChannel = false; 139 142 m_lastTypeBinary = -1; 143 m_bEnableKeepAlive = false; 144 m_keepAliveTimer.SetOwner(this, KEEPALIVE_TIMER_ID); 140 145 } 141 146 142 147 CFtpControlSocket::~CFtpControlSocket() … … 147 152 { 148 153 LogMessage(Debug_Verbose, _T("CFtpControlSocket::OnReceive()")); 149 154 155 m_keepAliveStopWatch.Start(); 156 150 157 m_pBackend->Read(m_receiveBuffer + m_bufferLen, RECVBUFFERSIZE - m_bufferLen); 151 158 152 159 if (m_pBackend->Error()) 153 160 { 154 161 if (m_pBackend->LastError() != wxSOCKET_WOULDBLOCK) 155 162 { 163 m_bEnableKeepAlive = false; 164 m_keepAliveTimer.Stop(); 156 165 LogMessage(::Error, _("Disconnected from server")); 157 166 DoClose(); 158 167 } … … 386 395 case cmd_rawtransfer: 387 396 TransferParseResponse(); 388 397 break; 398 case cmd_keepalive: 399 KeepAliveParseResponse(); 400 break; 389 401 case cmd_none: 390 402 LogMessage(Debug_Verbose, _T("Out-of-order reply, ignoring.")); 391 403 break; … … 798 810 LogMessage(::Error, _T("Failed to convert command to 8 bit charset")); 799 811 return false; 800 812 } 813 m_keepAliveStopWatch.Start(); 801 814 unsigned int len = (unsigned int)strlen(buffer); 802 815 bool res = CRealControlSocket::Send(buffer, len); 803 816 if (res) … … 1254 1267 return DeleteSend(prevResult); 1255 1268 case cmd_removedir: 1256 1269 return RemoveDirSend(prevResult); 1270 case cmd_keepalive: 1271 return KeepAliveSend(); 1257 1272 default: 1258 1273 LogMessage(__TFILE__, __LINE__, this, ::Debug_Warning, _T("Unknown opID (%d) in SendNextCommand"), m_pCurOpData->opId); 1259 1274 ResetOperation(FZ_REPLY_INTERNALERROR); … … 3006 3021 } 3007 3022 3008 3023 return FZ_REPLY_WOULDBLOCK; 3024 } 3025 3026 class CKeepAliveOpData : public COpData 3027 { 3028 public: 3029 CKeepAliveOpData(const wxString& command) 3030 : COpData(cmd_keepalive) 3031 { 3032 m_command = command; 3033 } 3034 3035 wxString m_command; 3036 }; 3037 3038 int CFtpControlSocket::KeepAlive(const CKeepAliveCommand& command) 3039 { 3040 LogMessage(Debug_Verbose, _T("CFtpControlSocket::KeepAlive")); 3041 3042 if (command.IsKeepAlive()) 3043 { 3044 if (!m_bEnableKeepAlive) 3045 { 3046 m_bEnableKeepAlive = true; 3047 // FIXME: 3048 // read keepalive option here 3049 int min_wait = 30; 3050 int max_wait = 60; 3051 int waitsecond = min_wait + (int)(rand()*(max_wait - min_wait)/(RAND_MAX+1)); 3052 m_keepAliveTimer.Start(waitsecond * 1000); 3053 } 3054 } 3055 else 3056 { 3057 if (m_bEnableKeepAlive) 3058 { 3059 m_bEnableKeepAlive = false; 3060 m_keepAliveTimer.Stop(); 3061 } 3062 } 3063 3064 m_bEnableKeepAlive = true; 3065 return FZ_REPLY_OK; 3066 } 3067 3068 int CFtpControlSocket::DoKeepAlive() 3069 { 3070 LogMessage(Debug_Verbose, _T("CFtpControlSocket::DoKeepAlive")); 3071 3072 // ignore keepalive for last I/O for socket less than 15 seconds 3073 if (m_keepAliveStopWatch.Time() < 15000) 3074 return FZ_REPLY_OK; 3075 // choose any command 3076 wxString commands[6] = {_T("PWD"),_T("REST 0"), _T("NOOP"), _T("STAT"), _T("RMD"), _T("MKD") }; 3077 int choice=(rand()*6)/(RAND_MAX+1); 3078 m_pCurOpData = new CKeepAliveOpData(commands[choice]); 3079 3080 return SendNextCommand(); 3081 } 3082 3083 int CFtpControlSocket::KeepAliveSend() 3084 { 3085 LogMessage(Debug_Verbose, _T("CFtpControlSocket::KeepAliveSend")); 3086 3087 if (!m_pCurOpData) 3088 { 3089 LogMessage(__TFILE__, __LINE__, this, Debug_Info, _T("Empty m_pCurOpData")); 3090 ResetOperation(FZ_REPLY_INTERNALERROR); 3091 return FZ_REPLY_ERROR; 3092 } 3093 3094 CDirectoryCache cache; 3095 cache.InvalidateServer(*m_pCurrentServer); 3096 m_CurrentPath = CServerPath(); 3097 3098 CKeepAliveOpData *pData = static_cast<CKeepAliveOpData *>(m_pCurOpData); 3099 3100 if (!Send(pData->m_command)) 3101 return FZ_REPLY_ERROR; 3102 3103 return FZ_REPLY_WOULDBLOCK; 3104 } 3105 3106 int CFtpControlSocket::KeepAliveParseResponse() 3107 { 3108 LogMessage(Debug_Verbose, _T("CFtpControlSocket::KeepAliveParseResponse")); 3109 3110 int code = GetReplyCode(); 3111 if (code == 2 || code == 3 || code == 5) 3112 { 3113 ResetOperation(FZ_REPLY_OK); 3114 return FZ_REPLY_OK; 3115 } 3116 else 3117 { 3118 ResetOperation(FZ_REPLY_ERROR); 3119 return FZ_REPLY_ERROR; 3120 } 3121 } 3122 3123 void CFtpControlSocket::OnTimer(wxTimerEvent& event) 3124 { 3125 if (event.GetId() == KEEPALIVE_TIMER_ID) 3126 { 3127 if (m_keepAliveTimer.IsRunning()) 3128 { 3129 m_keepAliveTimer.Stop(); 3130 if (m_bEnableKeepAlive) { 3131 // FIXME: 3132 // need to read the values from options... 3133 int min_wait = 30; 3134 int max_wait = 60; 3135 3136 int waitsecond = min_wait + (int)(rand()*(max_wait - min_wait)/(RAND_MAX+1)); 3137 m_keepAliveTimer.Start(waitsecond * 1000); 3138 DoKeepAlive(); 3139 } 3140 } 3141 } 3142 else 3143 CControlSocket::OnTimer(event); 3009 3144 } 3010 3145 3011 3146 bool CFtpControlSocket::IsMisleadingListResponse() const -
src/engine/ftpcontrolsocket.h
diff -Nur Filezilla3/src/engine/ftpcontrolsocket.h Filezilla3.patch/src/engine/ftpcontrolsocket.h
old new 24 24 25 25 protected: 26 26 27 bool m_bEnableKeepAlive; 28 wxTimer m_keepAliveTimer; 29 wxStopWatch m_keepAliveStopWatch; 30 virtual int KeepAlive(const CKeepAliveCommand& command); 31 int DoKeepAlive(); 32 int KeepAliveParseResponse(); 33 int KeepAliveSend(); 34 27 35 virtual int ResetOperation(int nErrorCode); 28 36 29 37 virtual int Connect(const CServer &server); … … 128 136 129 137 DECLARE_EVENT_TABLE(); 130 138 void OnExternalIPAddress(fzExternalIPResolveEvent& event); 139 void OnTimer(wxTimerEvent& event); 131 140 }; 132 141 133 142 class CIOThread; -
src/include/commands.h
diff -Nur Filezilla3/src/include/commands.h Filezilla3.patch/src/include/commands.h
old new 19 19 cmd_rename, 20 20 cmd_chmod, 21 21 cmd_raw, 22 cmd_keepalive, 22 23 23 24 // Only used internally 24 25 cmd_cwd, … … 74 75 const CServer GetServer() const; 75 76 protected: 76 77 CServer m_Server; 78 }; 79 80 DECLARE_COMMAND(CKeepAliveCommand, cmd_keepalive) 81 CKeepAliveCommand(bool keepAlive = true); 82 83 bool IsKeepAlive() const; 84 85 protected: 86 bool m_keepAlive; 77 87 }; 78 88 79 89 DECLARE_COMMAND(CDisconnectCommand, cmd_disconnect) -
src/include/engineprivate.h
diff -Nur Filezilla3/src/include/engineprivate.h Filezilla3.patch/src/include/engineprivate.h
old new 69 69 int Mkdir(const CMkdirCommand& command); 70 70 int Rename(const CRenameCommand& command); 71 71 int Chmod(const CChmodCommand& command); 72 int KeepAlive(const CKeepAliveCommand& command); 72 73 73 74 int ContinueConnect(); 74 75 -
src/interface/Mainfrm.cpp
diff -Nur Filezilla3/src/interface/Mainfrm.cpp Filezilla3.patch/src/interface/Mainfrm.cpp
old new 825 825 826 826 CServerPath path; 827 827 path.SetSafePath(COptions::Get()->GetOption(OPTION_LASTSERVERPATH)); 828 m_pState->Connect(server, false, path); 828 // FIXME: 829 // read keepalive from option 830 bool keepAlive = true; 831 m_pState->Connect(server, false, path, keepAlive); 829 832 } 830 833 831 834 void CMainFrame::OnRefresh(wxCommandEvent &event) … … 1341 1344 return; 1342 1345 } 1343 1346 1344 m_pState->Connect(pData->m_server, true, pData->m_remoteDir); 1347 // FIXME: 1348 // read keepalive from option 1349 bool keepAlive = true; 1350 m_pState->Connect(pData->m_server, true, pData->m_remoteDir, keepAlive); 1345 1351 1346 1352 if (pData->m_localDir != _T("")) 1347 1353 m_pState->SetLocalDir(pData->m_localDir); -
src/interface/state.cpp
diff -Nur Filezilla3/src/interface/state.cpp Filezilla3.patch/src/interface/state.cpp
old new 247 247 NotifyHandlers(STATECHANGE_APPLYFILTER); 248 248 } 249 249 250 bool CState::Connect(const CServer& server, bool askBreak, const CServerPath& path /*=CServerPath()*/ )250 bool CState::Connect(const CServer& server, bool askBreak, const CServerPath& path /*=CServerPath()*/, bool keepAlive) 251 251 { 252 252 if (!m_pEngine) 253 253 return false; … … 261 261 262 262 m_pCommandQueue->ProcessCommand(new CConnectCommand(server)); 263 263 m_pCommandQueue->ProcessCommand(new CListCommand(path)); 264 if (keepAlive) 265 m_pCommandQueue->ProcessCommand(new CKeepAliveCommand(true)); 264 266 265 267 COptions::Get()->SetLastServer(server); 266 268 COptions::Get()->SetOption(OPTION_LASTSERVERPATH, path.GetSafePath()); -
src/interface/state.h
diff -Nur Filezilla3/src/interface/state.h Filezilla3.patch/src/interface/state.h
old new 40 40 static bool LocalDirHasParent(const wxString& dir); 41 41 static bool LocalDirIsWriteable(const wxString& dir); 42 42 43 bool Connect(const CServer& server, bool askBreak, const CServerPath& path = CServerPath() );43 bool Connect(const CServer& server, bool askBreak, const CServerPath& path = CServerPath(), bool keepAlive = false); 44 44 45 45 bool SetRemoteDir(const CDirectoryListing *m_pDirectoryListing, bool modified = false); 46 46 const CDirectoryListing *GetRemoteDir() const;