#include "Synchronization.h" #include "Logger.h" #include "RcSyncdRequestData.h" #include "ProcessSocketControl.h" #include "ServiceConfig.h" #include #include #include #include #include #include CSynchronization::CSynchronization(CSyncInfo &info) : m_syncinfo(info) { } CSynchronization::~CSynchronization() { } int CSynchronization::ExcuteSync() { std::string strMessage; std::string strErrorMessage; CReqSyncData request; request.sync_type = m_syncinfo.sync_type; request.start_time = m_syncinfo.start_time; request.end_time = m_syncinfo.end_time; request.master = m_syncinfo.sync_master; request.slave = m_syncinfo.sync_slave; // get file size struct stat resultFileStat; if( stat( m_syncinfo.file_sync_name.c_str(), &resultFileStat ) != 0 ) { // ÇØ´ç ÆÄÀÏ¿¡ ´ëÇÑ stat Á¤º¸ ÃßÃâ ½ÇÆÐ½Ã. int errorNum = errno; char tempBuffer[1024]; if( errno != ENOENT ) { snprintf( tempBuffer, sizeof( tempBuffer ) - 1, "sync file mode file[%s] stat check fail [%d][%s]" , m_syncinfo.file_sync_name.c_str() , errorNum, strerror( errorNum ) ); strErrorMessage = tempBuffer; LOG( LERR, "%s", strErrorMessage.c_str() ); return -1; } else { // ÆÄÀÏÀÌ Á¸Àç ÇÏÁö ¾Ê´Â °æ¿ì´Â ½ÌÅ© ´ë»ó ¸ñ·ÏÀÌ ¾ø´Ù´Â °ÍÀ̱⠶§¹®¿¡ ¼º°øÀ¸·Î °£ÁÖÇÑ´Ù. LOG( LINF, "Not exist sync file.[%s]", strErrorMessage.c_str() ); return 0; } } // check ¸ðµå ÀÎ °æ¿ì ´Ü¼ø ¸®ÅÏÇÔ if (m_syncinfo.sync_type > SYNC_TYPE::NORMA_N_ONLY) return 1; // ÆÄÀÏ size ÃßÃâ. unsigned long long nFileSize = resultFileStat.st_size; // fd open int resultFd = open( m_syncinfo.file_sync_name.c_str(), O_RDONLY ); if( resultFd == -1 ) { int errorNum = errno; char tempBuffer[1024]; snprintf( tempBuffer, sizeof( tempBuffer ) - 1, "sync file mode result file[%s] open fail [%d][%s]" , m_syncinfo.file_sync_name.c_str() , errorNum, strerror( errorNum )); strErrorMessage = tempBuffer; LOG( LERR, "%s", strErrorMessage.c_str() ); return -2; } // Slave rc_syncd Á¢¼Ó ¹× content Á¤º¸ ¿äû CProcessSocketControl slave; slave.ConnectTarget(m_syncinfo.sync_rcts, CServiceConfig::GetInstance()->GetOperationPort()); if( slave.SendRequestExecuteSyncToSlave( request, resultFd, nFileSize, strMessage ) == false ) { // Àü¼Û ½ÇÆÐ½Ã _LOG( LERR, "%s", strMessage.c_str()); close(resultFd); slave.Close(); return -3; } _LOG( LDBG, "%s", strMessage.c_str()); close(resultFd); slave.Close(); return 1; }