diff --git a/src/Client.cpp b/src/Client.cpp index 0294aaf8816631390eaf3cba53ad53dfe19e8d0e..f43785c2fbcc2cac3c0f32a02e30b3eca2d1116d 100644 --- a/src/Client.cpp +++ b/src/Client.cpp @@ -38,7 +38,7 @@ Client::~Client() if(m_thread_sp) { - m_thread_sp->interrupt(); + //m_thread_sp->interrupt(); m_thread_sp->join(); } @@ -82,7 +82,7 @@ void Client::stop() if(m_thread_sp) { - m_thread_sp->interrupt(); + //m_thread_sp->interrupt(); m_thread_sp->join(); } @@ -411,6 +411,8 @@ void Client::handleReadData(FileWrapper::SP fileWrapper_sp, std::size_t recvByte { WARN_STREAM << "Client::handleReadData() bad I/O" << endl; + fileWrapper_sp->cleanUp(); + onTransferFailed(); } } diff --git a/src/Client.h b/src/Client.h index b5dfdf77c61b5cd97ec2c66b733b97fc74f5b3f5..f45abe8ca61f5b4624eb82496a0ca157270df5a6 100644 --- a/src/Client.h +++ b/src/Client.h @@ -117,7 +117,7 @@ protected: const boost::system::error_code&); //------------------------------------------------------------------------------ -// [Protected] Transfer result methods +// [Protected] Protocol and transfer result handler methods //------------------------------------------------------------------------------ void onTransferCompleted(FileWrapper::SP); diff --git a/src/ProtocolManager.cpp b/src/ProtocolManager.cpp index c9fc82b3ec40e2e7ce75366d04ee99102571be27..e76bc7fcdf8716320446a62194b3a1acb6bbf9a0 100644 --- a/src/ProtocolManager.cpp +++ b/src/ProtocolManager.cpp @@ -80,23 +80,35 @@ bool ProtocolManager::hasNextFile() m_recoveryMode = false; return true; } - else if(m_failedFileRowset_sp && + + if(m_failedFileRowset_sp && m_failedFileRowsetIt != m_failedFileRowset_sp->end()) { - DEBUG_STREAM << "ProtocolManager::hasNextFile() from failed list" << endl; + boost::posix_time::ptime now(boost::posix_time::second_clock::local_time()); - //FIXME: inhibition of retry for n seconds + if(m_recoveryModeTime.is_not_a_date_time()) + m_recoveryModeTime = now; - m_recoveryMode = true; - return true; - } - else - { - DEBUG_STREAM << "ProtocolManager::hasNextFile() lists empty" << endl; + boost::posix_time::time_duration diff = now - m_recoveryModeTime; - m_recoveryMode = false; - return false; + if(diff.total_seconds() > 30) + { + DEBUG_STREAM << "ProtocolManager::hasNextFile() from failed list" << endl; + m_recoveryModeTime = now; + m_recoveryMode = true; + return true; + } + else + { + DEBUG_STREAM << "ProtocolManager::hasNextFile() " + << "wait from failed list" << endl; + } } + + DEBUG_STREAM << "ProtocolManager::hasNextFile() lists empty" << endl; + + m_recoveryMode = false; + return false; } //============================================================================== @@ -280,6 +292,7 @@ void ProtocolManager::setFileTransfered(FileWrapper::SP fileWrapper_sp) throw std::invalid_argument("Empty file name found on failed list"); string fileName = m_failedFileRowsetIt->get<1>().get(); + //FIXME: not incremented in case of exception!!! ++m_failedFileRowsetIt; DBManager::TransactionSP auxTransaction_sp = m_dBManager_sp->getAuxTransaction(); @@ -315,9 +328,40 @@ void ProtocolManager::setFileFailed() throw(std::logic_error, std::runtime_error throw std::invalid_argument("Empty file name found on new list"); string fileName = m_newFileRowsetIt->get<1>().get(); + if(!m_newFileRowsetIt->get<2>()) + throw std::invalid_argument("Empty update time found on new list"); + std::tm currentTm = m_newFileRowsetIt->get<2>().get(); + + INFO_STREAM << "ProtocolManager::setFileFailed() file " + << fileName << " version " << fileVersion << " transfered" << endl; + + boost::posix_time::ptime currentPtime = + boost::posix_time::ptime_from_tm(currentTm); + + boost::posix_time::ptime nextPtime(boost::posix_time::pos_infin); + + //FIXME: not incremented in case of exception!!! ++m_newFileRowsetIt; + if(m_newFileRowsetIt != m_newFileRowset_sp->end()) + { + if(!m_newFileRowsetIt->get<2>()) + throw std::invalid_argument("Empty next update time found on new list"); + std::tm nextTm = m_newFileRowsetIt->get<2>().get(); + + nextPtime =boost::posix_time::ptime_from_tm(nextTm); + } + + DBManager::TransactionSP auxTransaction_sp = m_dBManager_sp->getAuxTransaction(); + DBManager::TransactionSP mainTransaction_sp = m_dBManager_sp->getMainTransaction(); + + if(nextPtime > currentPtime) + m_dBManager_sp->persistLastTimestamp(currentPtime); + m_dBManager_sp->addFailedFile(fileVersion, fileName); + + auxTransaction_sp->commit(); + mainTransaction_sp->commit(); } else { diff --git a/src/ProtocolManager.h b/src/ProtocolManager.h index 9cfc9913fc73305d03bc5eaeaa4ecce91be499df..b6b5a4d046acd6550cee2d990be3ed635dbc6a77 100644 --- a/src/ProtocolManager.h +++ b/src/ProtocolManager.h @@ -97,9 +97,12 @@ protected: //Address and port of remote endpoint std::string m_remoteEndpoint; - //Processing file from recovery list + //Processing file from failed list bool m_recoveryMode; + //Processing file from failed list last timestamp + boost::posix_time::ptime m_recoveryModeTime; + //New file list shared pointer DBManager::NewFileRowsetSP m_newFileRowset_sp;