📄 sock.cpp
字号:
// Sock.cpp : implementation file
//
#include "stdafx.h"
#include "netpro.h"
#include "Sock.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CSock
/// CSocket modify - timeout module.
BOOL CSock::ConnectHelper(const SOCKADDR* lpSockAddr, int nSockAddrLen)
{
if (m_pbBlocking != NULL)
{
WSASetLastError(WSAEINPROGRESS);
return FALSE;
}
m_nConnectError = -1;
if (!CAsyncSocket::ConnectHelper(lpSockAddr, nSockAddrLen))
{
if (GetLastError() == WSAEWOULDBLOCK)
{
// Insert....
CTime curt, st;
CTimeSpan span(0, 0, 0, m_nTimeOut);
st = CTime().GetCurrentTime();
//.......
while (PumpMessages(FD_CONNECT))
{
if (m_nConnectError != -1)
{
WSASetLastError(m_nConnectError);
return (m_nConnectError == 0);
}
// Insert....
curt = CTime().GetCurrentTime();
if(curt > (st+span))
return FALSE;
//..............
}
}
return FALSE;
}
m_Kill = FALSE;
return TRUE;
}
void CSock::OnClose(int nErrorCode)
{
m_Kill = TRUE;
}
// Do not edit the following lines, which are needed by ClassWizard.
#if 0
BEGIN_MESSAGE_MAP(CSock, CSocket)
//{{AFX_MSG_MAP(CSock)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
#endif // 0
/////////////////////////////////////////////////////////////////////////////
// CSock member functions
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -