Ejemplo n.º 1
0
void got_incoming_connection(void *userdata, struct UTPSocket *socket)
{
	CUTPSocketListner* pListner = ((CUTPSocketListner*)userdata);
	
	sockaddr_in6 sa; // sockaddr_in is smaller
	socklen_t sa_len = sizeof(sa);
	UTP_GetPeerName(socket, (sockaddr*)&sa, &sa_len);

	CUTPSocketListner::TKeyMap::iterator I = pListner->m_SendKeys.find((struct sockaddr*)&sa);
	if(I == pListner->m_SendKeys.end())
	{
		UTP_Close(socket);
		return;
	}
	ASSERT(I->second->PassKey);

	CSafeAddress Address((sockaddr*)&sa, sa_len, sa_len == sizeof(sockaddr_in) ? CSafeAddress::eUTP_IP4 : CSafeAddress::eUTP_IP6);
	Address.SetPassKey(I->second->PassKey);

	CSmartSocket* pSocket = pListner->GetParent<CSmartSocket>();
	CUTPSocketSession* pSession = new CUTPSocketSession(pListner, socket, Address);
	
	UTPFunctionTable utp_callbacks = {&utp_read, &utp_write, &utp_get_rb_size, &utp_state, &utp_error, &utp_overhead};
	UTP_SetCallbacks(socket, &utp_callbacks, pSession);

	pSocket->InsertSession(pSession);
}
Ejemplo n.º 2
0
Socket *Socket::accept(struct sockaddr *sa, socklen_t *salen)
{
    Socket *newsock = next;
    if (newsock) {
        next = newsock->next;
        newsock->next = NULL;
        UTP_GetPeerName(newsock->utp_sock, sa, salen);
    }
    return newsock;
}