//設置超時
![](http://static.javashuo.com/static/loading.gif)
BOOL CClientSocket::SetTimeOut(UINT uTimeOut)
![](http://static.javashuo.com/static/loading.gif)
{
![](http://static.javashuo.com/static/loading.gif)
m_nTimerID = SetTimer(NULL,0,uTimeOut,NULL);
return m_nTimerID;
![](http://static.javashuo.com/static/loading.gif)
}
//取消設置超時
![](http://static.javashuo.com/static/loading.gif)
BOOL CClientSocket::KillTimeOut()
![](http://static.javashuo.com/static/loading.gif)
{
return KillTimer(NULL,m_nTimerID);
![](http://static.javashuo.com/static/loading.gif)
}
//用於CSocket函數阻塞時,若是超時,則退出該阻塞函數
![](http://static.javashuo.com/static/loading.gif)
BOOL CClientSocket::OnMessagePending()
![](http://static.javashuo.com/static/loading.gif)
{
![](http://static.javashuo.com/static/loading.gif)
MSG msg;
if(::PeekMessage(&msg, NULL, WM_TIMER, WM_TIMER, PM_NOREMOVE)) {
if (msg.wParam == (UINT) m_nTimerID) {
![](http://static.javashuo.com/static/loading.gif)
::PeekMessage(&msg, NULL, WM_TIMER, WM_TIMER, PM_REMOVE);
![](http://static.javashuo.com/static/loading.gif)
CancelBlockingCall();
return FALSE;
![](http://static.javashuo.com/static/loading.gif)
};
![](http://static.javashuo.com/static/loading.gif)
};
return CSocket::OnMessagePending();
![](http://static.javashuo.com/static/loading.gif)
}