![]()
// 自己计算时间的办法 OK
![]()
public:
![]()
BOOL SetTimeOut(UINT uTimeOut=1000);
![]()
BOOL KillTimeOut();
![]()
private:
![]()
LONGLONG m_llDtStart;
![]()
UINT m_uTimeOut;
![]()
};
/////////////////////////////////////////////////////////////////////////////
//{{AFX_INSERT_LOCATION}}
![]()
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
#endif // !defined(AFX_TIMEOUTSOCK_H__19897A81_4EAF_4005_91FD_DC3047725139__INCLUDED_)
// TimeOutSock.cpp : implementation file
![]()
//
#include "stdafx.h"
![]()
#include "NetBroad.h"
![]()
#include "TimeOutSock.h"
#ifdef _DEBUG
![]()
#define new DEBUG_NEW
![]()
#undef THIS_FILE
![]()
static char THIS_FILE[] = __FILE__;
![]()
#endif
/////////////////////////////////////////////////////////////////////////////
![]()
// CTimeOutSock
CTimeOutSock::CTimeOutSock()
![]()
{
}
CTimeOutSock::~CTimeOutSock()
![]()
{
![]()
}
![]()
// Do not edit the following lines, which are needed by ClassWizard.
![]()
# if 0
![]()
BEGIN_MESSAGE_MAP(CTimeOutSock, CSocket)
![]()
//{{AFX_MSG_MAP(CTimeOutSock)
![]()
//}}AFX_MSG_MAP
![]()
END_MESSAGE_MAP()
![]()
#endif // 0
/////////////////////////////////////////////////////////////////////////////
![]()
// CTimeOutSock member functions
//设置超时
![]()
BOOL CTimeOutSock::SetTimeOut(UINT uTimeOut)
![]()
{
![]()
//get start cnt
![]()
LARGE_INTEGER llCnt;
![]()
::QueryPerformanceCounter(&llCnt);
![]()
m_llDtStart=llCnt.QuadPart;
![]()
m_uTimeOut=uTimeOut;
return TRUE;
![]()
}
//删除超时参数
![]()
BOOL CTimeOutSock::KillTimeOut()
![]()
{
![]()
m_llDtStart=0; //表明取消计时
![]()
return TRUE;
![]()
}
//检查是否超时间
![]()
BOOL CTimeOutSock::OnMessagePending()
![]()
{
![]()
// TODO: Add your specialized code here and/or call the base class
![]()
/*
![]()
MSG msg;
![]()
if(::PeekMessage(&msg, NULL, WM_TIMER, WM_TIMER, PM_NOREMOVE))
![]()
{
![]()
if (msg.wParam == (UINT) m_nTimerID)
![]()
{
![]()
// Remove the message and call CancelBlockingCall.
![]()
::PeekMessage(&msg, NULL, WM_TIMER, WM_TIMER, PM_REMOVE);
![]()
CancelBlockingCall();
![]()
return FALSE; // No need for idle time processing.
![]()
};
![]()
};
![]()
*/
![]()
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();
![]()
return FALSE; // No need for idle time processing.
![]()
}
![]()
}
![]()
return CSocket::OnMessagePending();
![]()
}