Example #1
0
TCPSocket*	TCPSocket::accept()
{
	TCPSocket *pNewSocket = new TCPSocket;
	sockaddr_in	conAddr;
	memset(&conAddr, 0, sizeof(conAddr));
	int nAddrLen = sizeof(conAddr);

	SOCKET hConnSocket = ::accept(m_hSocket, (sockaddr*)&conAddr, &nAddrLen);
	if(INVALID_SOCKET == hConnSocket)
	{
		Logger::getInstace()->error("TCPSocket >> accept 返回一个INVALID_SOCKET");
		delete pNewSocket;
		return NULL;
	}
	pNewSocket->attach(hConnSocket);
	pNewSocket->setPeerAddr(conAddr);
	return pNewSocket;
}