📄 warsvrprotocolftpdataconn.cpp
字号:
#include "StdAfx.h"#include "WarSvrProtocolFtpDataConn.h" // class implemented#ifndef WAR_AUTO_LOCK_H# include "WarAutoLock.h"#endif#ifndef WAR_SVR_PROTOCOL_FTP_H# include "WarSvrProtocolFtp.h"#endif#ifndef WAR_FILE_DRIVER_FILE_H# include "WarFileDriverFile.h"#endif#ifndef WAR_LOG_H# include "WarLog.h"#endif#ifndef WAR_PERFMON_DEF_H# include "WarPerfmonDef.h"#endif#ifndef WAR_FUNCTION_PROFILER_H# include "WarFunctionProfiler.h"#endif#ifndef WAR_SOCKET_CPS_LIMIT_H# include "WarSocketCpsLimit.h"#endif#define AUTO_LOCK WarAutoLock my_lock((WarCriticalSection *)pmLock)/////////////////////////////// PUBLIC /////////////////////////////////////////============================= LIFECYCLE ====================================WarSvrProtocolFtpDataConn::WarSvrProtocolFtpDataConn( war_socket_io_ptr_t& companionPtr, WarSvrProtocolFtp& rServer): WarTransferSocket(companionPtr),mrServer(rServer){ WarLog debug_log(WARLOG_DEBUG, "WarSvrProtocolFtpDataConn::WarSvrProtocolFtpDataConn()", this); WAR_DB_PERFMON_INC(WAR_PRFDEBUG_NUM_FTPDATA); AddLogIdentifierTag("DATA"); std::string log_identifier; mrServer.GetLogIdentifier(log_identifier); AddLogIdentifierTag(log_identifier.c_str()); if (debug_log) debug_log << "Creating FTP data socket " << war_endl; mLockOwner = &mrServer; pmLock = &mrServer.mSvrLock; SetTransferMode(TM_FAST);}// WarSvrProtocolFtpDataConnWarSvrProtocolFtpDataConn::~WarSvrProtocolFtpDataConn(){ WarLog debug_log(WARLOG_DEBUG, "WarSvrProtocolFtpDataConn::~WarSvrProtocolFtpDataConn()", this); if (debug_log) debug_log << "Destroying FTP data socket " << war_endl; WAR_DB_PERFMON_DEC(WAR_PRFDEBUG_NUM_FTPDATA);}// ~WarSvrProtocolFtpDataConn//============================= OPERATORS ====================================//============================= OPERATIONS ===================================void WarSvrProtocolFtpDataConn::SendFile(war_svrfile_ptr_t& filePtr){ int cps = mrServer.GetIntOption("ftpd_CPSOUTMAXCPS"); if (cps > 0) { try { WarSocketCpsLimit::GetModule().EnableCps( this, mrServer.GetIntOption("ftpd_CPSOUTSAMPLEDELAY"), mrServer.GetIntOption("ftpd_CPSOUTHOLDDELAY"), mrServer.GetIntOption("ftpd_CPSOUTMINCNT"), mrServer.GetIntOption("ftpd_CPSOUTMAXCNT"), mrServer.GetIntOption("ftpd_CPSOUTMINCPS"), cps, WarSocketCpsLimit::SENDING); } catch(WarException& ex) { WarLog err_log(WARLOG_ERROR, "WarSvrProtocolFtpDataConn::SendFile()", this); err_log << "Failed to set CPS limit. " << ex << war_endl; } } WarTransferSocket::SendFile(filePtr);}void WarSvrProtocolFtpDataConn::ReceiveFile(war_svrfile_ptr_t& filePtr){ int cps = mrServer.GetIntOption("ftpd_CPSINMAXCPS"); if (cps > 0) { try { WarSocketCpsLimit::GetModule().EnableCps( this, mrServer.GetIntOption("ftpd_CPSINSAMPLEDELAY"), mrServer.GetIntOption("ftpd_CPSINHOLDDELAY"), mrServer.GetIntOption("ftpd_CPSINMINCNT"), mrServer.GetIntOption("ftpd_CPSINMAXCNT"), mrServer.GetIntOption("ftpd_CPSINMINCPS"), cps, WarSocketCpsLimit::RECEIVING); } catch(WarException& ex) { WarLog err_log(WARLOG_ERROR, "WarSvrProtocolFtpDataConn::ReceiveFile()", this); err_log << "Failed to set CPS limit. " << ex << war_endl; } } WarTransferSocket::ReceiveFile(filePtr);}//============================= ACCESS ===================================//============================= INQUIRY ===================================/////////////////////////////// PROTECTED ///////////////////////////////////void WarSvrProtocolFtpDataConn::OnTransferDone(const WarError& status){ war_datasck_ptr_t my_ptr = this; { AUTO_LOCK; if (HasFinished()) return; WAR_PERFMON_DEC(WAR_PRFSVR_TRANSFERS_NOW); if (status) { WAR_PERFMON_INC(WAR_PRFSVR_TRANSFERS_FAILED); } else { WAR_PERFMON_INC(WAR_PRFSVR_TRANSFERS_TOTAL); } mrServer.OnTransferDone(status); WarTransferSocket::OnTransferDone(status); // Cleanup assert(IsOpen() == false); }}void WarSvrProtocolFtpDataConn::StartTransfer(war_svrfile_ptr_t& filePtr){ WAR_PERFMON_INC(WAR_PRFSVR_TRANSFERS_NOW) // Set transfer parameters mNumBufSegments = mrServer.GetIntOption("ftpd_DATABUFSEGMENTS"); if (mNumBufSegments < 1) mNumBufSegments = 1; mNumBuffers = mrServer.GetIntOption("ftpd_DATABUFCNT"); if (mNumBuffers < 1) mNumBuffers = 1; mBufferLen = mrServer.GetIntOption("ftpd_DATABUFSIZE"); if (mBufferLen < 512) mBufferLen = 512; mTimeOutSeconds = mrServer.GetIntOption("ftpd_DATATIMEOUT"); WarTransferSocket::StartTransfer(filePtr);}// Called when data is received in send-mode.void WarSvrProtocolFtpDataConn::OnReceived(const WarError& status, war_transfer_buffer_ptr_t& buffer){ assert(D_RECEIVING != mDirection); WarLog warn_log(WARLOG_WARNINGS, "WarSvrProtocolFtpDataConn::OnReceived()", this); warn_log << "Received input data in sendmode. This should not happen. Aborting transfer." << war_endl; OnTransferDone(WarError(WAR_ERR_NOT_OPEN_FOR_READ)); return;}void WarSvrProtocolFtpDataConn::OnSent(const WarError& status, war_transfer_buffer_ptr_t& buffer){ assert(false);}/////////////////////////////// PRIVATE ///////////////////////////////////
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -