忘记屏蔽副机,且副机没开时.不会再阻塞卡死

同兴达分出-改到信利(不推治具)
bestlqiang 4 years ago
parent af775a1c1c
commit 01ce2b3263

@ -53,6 +53,7 @@ void CClientMgr::DisConnectServer()
if (m_hSocket!=INVALID_SOCKET) if (m_hSocket!=INVALID_SOCKET)
{ {
Close(); Close();
m_bOnline = false;
} }
} }
@ -322,6 +323,48 @@ void CClientMgr::OnConnect(int nErrorCode)
CSocket::OnConnect(nErrorCode); CSocket::OnConnect(nErrorCode);
} }
BOOL CClientMgr::Connect(LPCTSTR lpszHostAddress, UINT nHostPort)
{
SetTimeOut();
auto ret = CSocket::Connect(lpszHostAddress, nHostPort);
KillTimeOut();
return ret;
}
BOOL CClientMgr::SetTimeOut(UINT uTimeOut)
{
LARGE_INTEGER llCnt;
::QueryPerformanceCounter(&llCnt);
m_llDtStart = llCnt.QuadPart;
m_uTimeOut = uTimeOut;
return TRUE;
}
BOOL CClientMgr::KillTimeOut()
{
m_llDtStart = 0;//表明取消计时
return TRUE;
}
BOOL CClientMgr::OnMessagePending()
{
if (m_llDtStart)
{
LARGE_INTEGER lldtEnd;
::QueryPerformanceCounter(&lldtEnd);
LARGE_INTEGER llFrq;
::QueryPerformanceFrequency(&llFrq);
double dbDealy = (double)(lldtEnd.QuadPart - m_llDtStart) * 1000 / llFrq.QuadPart;
if (dbDealy > m_uTimeOut)
{
CancelBlockingCall();//退出阻塞的函数
AfxMessageBox("网络超时!");
return FALSE; // No need for idle time processing.
}
}
return CSocket::OnMessagePending();
}
bool CClientMgr::CheckServerDoneCmd() bool CClientMgr::CheckServerDoneCmd()
{ {
int waitCnt = 0; int waitCnt = 0;

@ -61,6 +61,19 @@ private:
virtual void OnReceive(int nErrorCode); virtual void OnReceive(int nErrorCode);
virtual void OnClose(int nErrorCode); virtual void OnClose(int nErrorCode);
virtual void OnConnect(int nErrorCode); virtual void OnConnect(int nErrorCode);
//start--------------设定发送超时---------------------
private:
//virtual int Send(const void* lpBuf, int nBufLen, int nFlags = 0) override; //重写 加入超时
virtual BOOL Connect(LPCTSTR lpszHostAddress, UINT nHostPort); //重写 加入超时
BOOL SetTimeOut(UINT uTimeOut = 500);//ms级延时
BOOL KillTimeOut();
virtual BOOL OnMessagePending() override;
LONGLONG m_llDtStart;
UINT m_uTimeOut;
//end--------------设定读写超时相关---------------------
void SendCmd_TransFile(CString filePath);//给伺服端传文件(复制到共享盘,无通信) void SendCmd_TransFile(CString filePath);//给伺服端传文件(复制到共享盘,无通信)
void DoEvents(); void DoEvents();
bool m_bOnline = false; bool m_bOnline = false;

Loading…
Cancel
Save