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

View file

@ -70,6 +70,7 @@ public:
void ResetTimeOutCounter() { iConTimeOut = iConTimeOutStartVal; } void ResetTimeOutCounter() { iConTimeOut = iConTimeOutStartVal; }
bool IsConnected() const { return iConTimeOut > 0; } bool IsConnected() const { return iConTimeOut > 0; }
void Disconnect();
void SetEnable ( const bool bNEnStat ); void SetEnable ( const bool bNEnStat );
bool IsEnabled() { return bIsEnabled; } bool IsEnabled() { return bIsEnabled; }
@ -173,7 +174,7 @@ public slots:
void OnChangeChanName ( QString strName ); void OnChangeChanName ( QString strName );
void OnNetTranspPropsReceived ( CNetworkTransportProps NetworkTransportProps ); void OnNetTranspPropsReceived ( CNetworkTransportProps NetworkTransportProps );
void OnReqNetTranspProps(); void OnReqNetTranspProps();
void OnDisconnection(); void OnDisconnection() { Disconnect(); }
signals: signals:
void MessReadyForSending ( CVector<uint8_t> vecMessage ); 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 // network queue causing the channel to be reconnected right after having
// received the disconnect message (seems not to gain much, disconnect is // received the disconnect message (seems not to gain much, disconnect is
// still not working reliably) // still not working reliably)
QTime dieTime = QTime::currentTime().addMSecs ( 100 ); QTime DieTime = QTime::currentTime().addMSecs ( 100 );
while ( QTime::currentTime() < dieTime ) while ( QTime::currentTime() < DieTime )
{ {
QCoreApplication::processEvents ( QEventLoop::AllEvents, 100 ); QCoreApplication::processEvents ( QEventLoop::AllEvents, 100 );
} }

View file

@ -33,8 +33,8 @@ MAIN FRAME
MESSAGES MESSAGES (with connection)
-------- --------------------------
- PROTMESSID_ACKN: Acknowledgement message - PROTMESSID_ACKN: Acknowledgement message
@ -202,7 +202,6 @@ CONNECTION LESS MESSAGES
the QLocale class the QLocale class
- PROTMESSID_CLM_UNREGISTER_SERVER: Unregister a server - PROTMESSID_CLM_UNREGISTER_SERVER: Unregister a server
note: does not have any data -> n = 0 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 * 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: case PROTMESSID_CLM_UNREGISTER_SERVER:
bRet = EvaluateCLUnregisterServerMes ( InetAddr ); bRet = EvaluateCLUnregisterServerMes ( InetAddr );
break; break;
case PROTMESSID_CLM_DISCONNECTION:
bRet = EvaluateCLDisconnectionMes ( InetAddr );
break;
} }
} }
else else
@ -1568,11 +1576,28 @@ bool CProtocol::EvaluateCLSendEmptyMesMes ( const CVector<uint8_t>& vecData )
void CProtocol::CreateCLEmptyMes ( const CHostAddress& InetAddr ) void CProtocol::CreateCLEmptyMes ( const CHostAddress& InetAddr )
{ {
// special message: for this message there exist no Evaluate
// function
CreateAndImmSendConLessMessage ( PROTMESSID_CLM_EMPTY_MESSAGE, CreateAndImmSendConLessMessage ( PROTMESSID_CLM_EMPTY_MESSAGE,
CVector<uint8_t> ( 0 ), CVector<uint8_t> ( 0 ),
InetAddr ); 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 * * Message generation and parsing *

View file

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

View file

@ -304,6 +304,10 @@ CServer::CServer ( const int iNewNumChan,
SIGNAL ( CLSendEmptyMes ( CHostAddress ) ), SIGNAL ( CLSendEmptyMes ( CHostAddress ) ),
this, SLOT ( OnCLSendEmptyMes ( CHostAddress ) ) ); this, SLOT ( OnCLSendEmptyMes ( CHostAddress ) ) );
QObject::connect ( &ConnLessProtocol,
SIGNAL ( CLDisconnection ( CHostAddress ) ),
this, SLOT ( OnCLDisconnection ( CHostAddress ) ) );
// CODE TAG: MAX_NUM_CHANNELS_TAG // CODE TAG: MAX_NUM_CHANNELS_TAG
// make sure we have MAX_NUM_CHANNELS connections!!! // make sure we have MAX_NUM_CHANNELS connections!!!
@ -407,6 +411,18 @@ void CServer::OnSendCLProtMessage ( CHostAddress InetAddr,
Socket.SendPacket ( vecMessage, 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() void CServer::Start()
{ {
// only start if not already running // only start if not already running
@ -880,6 +896,21 @@ int CServer::GetFreeChan()
return INVALID_CHANNEL_ID; 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 CServer::GetNumberOfConnectedClients()
{ {
int iNumConnClients = 0; int iNumConnClients = 0;

View file

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

View file

@ -137,11 +137,19 @@ void CSocket::OnDataReceived()
// are not connected anymore // are not connected anymore
if ( pChannel->GetAddress() == RecHostAddr ) 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->SetEnable ( true );
pChannel->CreateAndImmSendDisconnectionMes(); pChannel->CreateAndImmSendDisconnectionMes();
pChannel->SetEnable ( false ); 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; break;
case 20: case 20:
Protocol.CreateAndImmSendAcknMess ( GenRandomIntInRange ( -10, 100 ), Protocol.CreateCLDisconnection ( CurHostAddress );
GenRandomIntInRange ( -100, 100 ) );
break; break;
case 21: case 21:
Protocol.CreateAndImmSendDisconnectionMes(); Protocol.CreateAndImmSendAcknMess ( GenRandomIntInRange ( -10, 100 ),
GenRandomIntInRange ( -100, 100 ) );
break; break;
case 22: case 22: