Example #1
0
Socket::~Socket()
{
    if (bound && udp_sock != -1)
        close(udp_sock);
    if (utp_sock)
        UTP_Close(utp_sock);
}
Example #2
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);
}
Example #3
0
void CUTPSocketSession::Close()
{
	if(m_Socket)
	{
		UTP_Close(m_Socket);
		UTP_SetCallbacks(m_Socket, NULL, NULL); // make sure this will not be refered anymore
	}
	m_Socket = NULL;
	m_State = UTP_STATE_EOF;
}