added a connection less message for disconnect -> does not work yet since connection less messages are not evaluated for connected channels

This commit is contained in:
Volker Fischer 2011-05-22 09:47:09 +00:00
parent f41f373ead
commit a770b75a06
9 changed files with 94 additions and 20 deletions

View file

@ -331,7 +331,7 @@ void CChannel::CreateNetTranspPropsMessFromCurrentSettings()
Protocol.CreateNetwTranspPropsMes ( NetworkTransportProps );
}
void CChannel::OnDisconnection()
void CChannel::Disconnect()
{
// set time out counter to a small value > 0 so that the next time a
// received audio block is queried, the disconnection is performed

View file

@ -70,6 +70,7 @@ public:
void ResetTimeOutCounter() { iConTimeOut = iConTimeOutStartVal; }
bool IsConnected() const { return iConTimeOut > 0; }
void Disconnect();
void SetEnable ( const bool bNEnStat );
bool IsEnabled() { return bIsEnabled; }
@ -173,7 +174,7 @@ public slots:
void OnChangeChanName ( QString strName );
void OnNetTranspPropsReceived ( CNetworkTransportProps NetworkTransportProps );
void OnReqNetTranspProps();
void OnDisconnection();
void OnDisconnection() { Disconnect(); }
signals:
void MessReadyForSending ( CVector<uint8_t> vecMessage );

View file

@ -425,8 +425,8 @@ void CClient::Stop()
// network queue causing the channel to be reconnected right after having
// received the disconnect message (seems not to gain much, disconnect is
// still not working reliably)
QTime dieTime = QTime::currentTime().addMSecs ( 100 );
while ( QTime::currentTime() < dieTime )
QTime DieTime = QTime::currentTime().addMSecs ( 100 );
while ( QTime::currentTime() < DieTime )
{
QCoreApplication::processEvents ( QEventLoop::AllEvents, 100 );
}

View file

@ -33,8 +33,8 @@ MAIN FRAME
MESSAGES
--------
MESSAGES (with connection)
--------------------------
- PROTMESSID_ACKN: Acknowledgement message
@ -202,7 +202,6 @@ CONNECTION LESS MESSAGES
the QLocale class
- PROTMESSID_CLM_UNREGISTER_SERVER: Unregister a server
note: does not have any data -> n = 0
@ -232,6 +231,11 @@ CONNECTION LESS MESSAGES
+--------------------+--------------+
- PROTMESSID_CLM_DISCONNECTION: Disconnect message
note: does not have any data -> n = 0
******************************************************************************
*
* This program is free software; you can redistribute it and/or modify it under
@ -616,6 +620,10 @@ if ( rand() < ( RAND_MAX / 2 ) ) return false;
case PROTMESSID_CLM_UNREGISTER_SERVER:
bRet = EvaluateCLUnregisterServerMes ( InetAddr );
break;
case PROTMESSID_CLM_DISCONNECTION:
bRet = EvaluateCLDisconnectionMes ( InetAddr );
break;
}
}
else
@ -1568,11 +1576,28 @@ bool CProtocol::EvaluateCLSendEmptyMesMes ( const CVector<uint8_t>& vecData )
void CProtocol::CreateCLEmptyMes ( const CHostAddress& InetAddr )
{
// special message: for this message there exist no Evaluate
// function
CreateAndImmSendConLessMessage ( PROTMESSID_CLM_EMPTY_MESSAGE,
CVector<uint8_t> ( 0 ),
InetAddr );
}
void CProtocol::CreateCLDisconnection ( const CHostAddress& InetAddr )
{
CreateAndImmSendConLessMessage ( PROTMESSID_CLM_DISCONNECTION,
CVector<uint8_t> ( 0 ),
InetAddr );
}
bool CProtocol::EvaluateCLDisconnectionMes ( const CHostAddress& InetAddr )
{
// invoke message action
emit CLDisconnection ( InetAddr );
return false; // no error
}
/******************************************************************************\
* Message generation and parsing *

View file

@ -64,6 +64,7 @@
#define PROTMESSID_CLM_REQ_SERVER_LIST 1007 // request server list
#define PROTMESSID_CLM_SEND_EMPTY_MESSAGE 1008 // an empty message shall be send
#define PROTMESSID_CLM_EMPTY_MESSAGE 1009 // empty message
#define PROTMESSID_CLM_DISCONNECTION 1010 // disconnection
// lengths of message as defined in protocol.cpp file
@ -110,10 +111,7 @@ public:
void CreateCLSendEmptyMesMes ( const CHostAddress& InetAddr,
const CHostAddress& TargetInetAddr );
void CreateCLEmptyMes ( const CHostAddress& InetAddr );
void CreateAndImmSendDisconnectionMes();
void CreateAndImmSendAcknMess ( const int& iID,
const int& iCnt );
void CreateCLDisconnection ( const CHostAddress& InetAddr );
bool ParseMessage ( const CVector<uint8_t>& vecbyData,
const int iNumBytes );
@ -125,6 +123,12 @@ public:
bool IsProtocolMessage ( const CVector<uint8_t>& vecbyData,
const int iNumBytes );
void CreateAndImmSendDisconnectionMes();
// this function is public because we need it in the test bench
void CreateAndImmSendAcknMess ( const int& iID,
const int& iCnt );
protected:
class CSendMessage
{
@ -219,6 +223,7 @@ protected:
const CVector<uint8_t>& vecData );
bool EvaluateCLReqServerListMes ( const CHostAddress& InetAddr );
bool EvaluateCLSendEmptyMesMes ( const CVector<uint8_t>& vecData );
bool EvaluateCLDisconnectionMes ( const CHostAddress& InetAddr );
int iOldRecID;
int iOldRecCnt;
@ -266,6 +271,7 @@ signals:
CVector<CServerInfo> vecServerInfo );
void CLReqServerList ( CHostAddress InetAddr );
void CLSendEmptyMes ( CHostAddress TargetInetAddr );
void CLDisconnection ( CHostAddress InetAddr );
};
#endif /* !defined ( PROTOCOL_H__3B123453_4344_BB2392354455IUHF1912__INCLUDED_ ) */

View file

@ -304,6 +304,10 @@ CServer::CServer ( const int iNewNumChan,
SIGNAL ( CLSendEmptyMes ( CHostAddress ) ),
this, SLOT ( OnCLSendEmptyMes ( CHostAddress ) ) );
QObject::connect ( &ConnLessProtocol,
SIGNAL ( CLDisconnection ( CHostAddress ) ),
this, SLOT ( OnCLDisconnection ( CHostAddress ) ) );
// CODE TAG: MAX_NUM_CHANNELS_TAG
// make sure we have MAX_NUM_CHANNELS connections!!!
@ -407,6 +411,18 @@ void CServer::OnSendCLProtMessage ( CHostAddress InetAddr,
Socket.SendPacket ( vecMessage, InetAddr );
}
void CServer::OnCLDisconnection ( CHostAddress InetAddr )
{
// check if the given address is actually a client which is connected to
// this server, if yes, disconnect it
const int iCurChanID = FindChannel ( InetAddr );
if ( iCurChanID != INVALID_CHANNEL_ID )
{
vecChannels[iCurChanID].Disconnect();
}
}
void CServer::Start()
{
// only start if not already running
@ -880,6 +896,21 @@ int CServer::GetFreeChan()
return INVALID_CHANNEL_ID;
}
int CServer::FindChannel ( const CHostAddress& InetAddr )
{
// look for a channel with the given internet address
for ( int i = 0; i < iNumChannels; i++ )
{
if ( vecChannels[i].GetAddress() == InetAddr )
{
return i;
}
}
// no free channel found, return invalid ID
return INVALID_CHANNEL_ID;
}
int CServer::GetNumberOfConnectedClients()
{
int iNumConnClients = 0;

View file

@ -183,6 +183,7 @@ protected:
int CheckAddr ( const CHostAddress& Addr );
int GetFreeChan();
int FindChannel ( const CHostAddress& InetAddr );
int GetNumberOfConnectedClients();
CVector<CChannelShortInfo> CreateChannelList();
void CreateAndSendChanListForAllConChannels();
@ -276,6 +277,8 @@ public slots:
ServerListManager.CentralServerUnregisterServer ( InetAddr );
}
void OnCLDisconnection ( CHostAddress InetAddr );
// CODE TAG: MAX_NUM_CHANNELS_TAG
// make sure we have MAX_NUM_CHANNELS connections!!!

View file

@ -137,11 +137,19 @@ void CSocket::OnDataReceived()
// are not connected anymore
if ( pChannel->GetAddress() == RecHostAddr )
{
// the channel has to be enabled for sending a message,
// disable the channel again afterwards
// TEST old code -> to be removed because this is not working!!!
pChannel->SetEnable ( true );
pChannel->CreateAndImmSendDisconnectionMes();
pChannel->SetEnable ( false );
// TODO this does not work because for a connected channel at the server, no
// connection less protocol messages are accepted
// pConnLessProtocol->CreateCLDisconnection ( RecHostAddr );
}
}

View file

@ -230,12 +230,12 @@ public slots:
break;
case 20:
Protocol.CreateAndImmSendAcknMess ( GenRandomIntInRange ( -10, 100 ),
GenRandomIntInRange ( -100, 100 ) );
Protocol.CreateCLDisconnection ( CurHostAddress );
break;
case 21:
Protocol.CreateAndImmSendDisconnectionMes();
Protocol.CreateAndImmSendAcknMess ( GenRandomIntInRange ( -10, 100 ),
GenRandomIntInRange ( -100, 100 ) );
break;
case 22: