碎片函数实现
bool Socket::ConnectEx(const char * Address, uint32 Port)
{
struct hostent * ci = gethostbyname(Address);
if(ci == 0)
return false;
SOCKADDR_IN addr;
addr.sin_family = AF_INET;
addr.sin_addr.s_addr = INADDR_ANY;
addr.sin_port = htons((short)0);
::bind(m_fd, (const sockaddr*)&addr, sizeof(addr));
BindIoCompletionCallback((HANDLE)m_fd, SocketMgr::NetIOCompletionRoutine, 0);
m_client.sin_family = ci->h_addrtype;
m_client.sin_port = ntohs((u_short)Port);
memcpy(&m_client.sin_addr.s_addr, ci->h_addr_list[0], ci->h_length);
LPFN_CONNECTEX pfnConnectEx;
GUID GuidConnectEx = WSAID_CONNECTEX;
DWORD dwBytes;
WSAIoctl(m_fd, SIO_GET_EXTENSION_FUNCTION_POINTER, &GuidConnectEx, sizeof(GuidConnectEx),
&pfnConnectEx, sizeof(pfnConnectEx), &dwBytes, NULL, NULL);
if (!pfnConnectEx)
{
return false;
}
m_writeEvent.Reset(this);
m_writeEvent.m_event = SOCKET_IO_EVENT_CONNECTING;
if (pfnConnectEx(m_fd, (const sockaddr*)&m_client, sizeof(SOCKADDR_IN), NULL, 0, NULL, &m_writeEvent.m_overlap))
{
}
return true;
}