Esempio 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);
}
Esempio n. 2
0
void Socket::_UTPGotIncomingConnection(void *userdata, struct UTPSocket *s)
{
    Socket *self = (Socket*)userdata;
    Socket *nextSocket = new Socket(s);
    nextSocket->next = self->next;
    self->next = nextSocket;
    nextSocket->address_family = self->address_family;
    nextSocket->udp_sock = self->udp_sock;
    UTP_SetCallbacks(nextSocket->utp_sock, &nextSocket->utp_funcs, nextSocket);
}
Esempio n. 3
0
int Socket::connect(struct sockaddr *sa, socklen_t salen)
{
    if (bindsocket() == -1)
        return -1;
    if (!utp_sock) {
        utp_sock = UTP_Create(_SendToProc, this, sa, salen);
        UTP_SetCallbacks(utp_sock, &utp_funcs, this);
    }
    UTP_Connect(utp_sock);
}
Esempio n. 4
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;
}
Esempio n. 5
0
void CUTPSocketSession::Connect(const struct sockaddr *sa, socklen_t sa_len)
{
	ASSERT(!IsValid());

	m_Socket = UTP_Create(&send_to, GetParent<CUTPSocketListner>(), sa, sa_len, &utp_overhead_2);
	//UTP_SetSockopt(m_Socket, SO_SNDBUF, 100*300);

	UTPFunctionTable utp_callbacks = {&utp_read, &utp_write, &utp_get_rb_size, &utp_state, &utp_error, &utp_overhead};
	UTP_SetCallbacks(m_Socket, &utp_callbacks, this);
	UTP_Connect(m_Socket);
}
Esempio n. 6
0
void CUTPSocketSession::Swap(CSocketSession* pNew)
{
	ASSERT(m_Socket == NULL);

	m_Socket = ((CUTPSocketSession*)pNew)->m_Socket;
	((CUTPSocketSession*)pNew)->m_Socket = NULL;
	m_LastActivity = GetCurTick();

	ASSERT(m_Socket);
	UTPFunctionTable utp_callbacks = {&utp_read, &utp_write, &utp_get_rb_size, &utp_state, &utp_error, &utp_overhead};
	UTP_SetCallbacks(m_Socket, &utp_callbacks, this);

	delete pNew;
}