removed old disconnect message which only works with connected channels -> replaced by a connection less disconnect message

This commit is contained in:
Volker Fischer 2011-05-23 19:06:02 +00:00
parent b7ce6c3193
commit b28daa079a
9 changed files with 101 additions and 94 deletions

View file

@ -93,6 +93,10 @@ CChannel::CChannel ( const bool bNIsServer ) :
SIGNAL ( PingReceived ( int ) ),
SIGNAL ( PingReceived ( int ) ) );
QObject::connect ( &Protocol,
SIGNAL ( DetectedCLMessage ( CVector<uint8_t>, int ) ),
SIGNAL ( DetectedCLMessage ( CVector<uint8_t>, int ) ) );
QObject::connect ( &Protocol,
SIGNAL ( NetTranspPropsReceived ( CNetworkTransportProps ) ),
this, SLOT ( OnNetTranspPropsReceived ( CNetworkTransportProps ) ) );
@ -100,9 +104,6 @@ CChannel::CChannel ( const bool bNIsServer ) :
QObject::connect ( &Protocol,
SIGNAL ( ReqNetTranspProps() ),
this, SLOT ( OnReqNetTranspProps() ) );
QObject::connect ( &Protocol, SIGNAL ( Disconnection() ),
this, SLOT ( OnDisconnection() ) );
}
bool CChannel::ProtocolIsEnabled()
@ -350,12 +351,16 @@ void CChannel::CreateNetTranspPropsMessFromCurrentSettings()
}
void CChannel::Disconnect()
{
// we only have to disconnect the channel if it is actually connected
if ( IsConnected() )
{
// set time out counter to a small value > 0 so that the next time a
// received audio block is queried, the disconnection is performed
// (assuming that no audio packet is received in the meantime)
iConTimeOut = 1; // a small number > 0
}
}
EPutDataStat CChannel::PutData ( const CVector<uint8_t>& vecbyData,
int iNumBytes )

View file

@ -138,8 +138,6 @@ void UpdateSocketBufferSize ( const double dAudioBufferDurationMs,
}
void CreateNetTranspPropsMessFromCurrentSettings();
void CreateAndImmSendDisconnectionMes()
{ Protocol.CreateAndImmSendDisconnectionMes(); }
protected:
bool ProtocolIsEnabled();
@ -186,7 +184,6 @@ public slots:
void OnChangeChanName ( QString strName );
void OnNetTranspPropsReceived ( CNetworkTransportProps NetworkTransportProps );
void OnReqNetTranspProps();
void OnDisconnection() { Disconnect(); }
signals:
void MessReadyForSending ( CVector<uint8_t> vecMessage );
@ -200,6 +197,8 @@ signals:
void PingReceived ( int iMs );
void ReqNetTranspProps();
void Disconnected();
void DetectedCLMessage ( CVector<uint8_t> vecbyData,
int iNumBytes );
};
#endif /* !defined ( CHANNEL_HOIH9345KJH98_3_4344_BB23945IUHF1912__INCLUDED_ ) */

View file

@ -83,6 +83,10 @@ CClient::CClient ( const quint16 iPortNumber ) :
SIGNAL ( MessReadyForSending ( CVector<uint8_t> ) ),
this, SLOT ( OnSendProtMessage ( CVector<uint8_t> ) ) );
QObject::connect ( &Channel,
SIGNAL ( DetectedCLMessage ( CVector<uint8_t>, int ) ),
this, SLOT ( OnDetectedCLMessage ( CVector<uint8_t>, int ) ) );
QObject::connect ( &Channel, SIGNAL ( ReqJittBufSize() ),
this, SLOT ( OnReqJittBufSize() ) );
@ -138,6 +142,16 @@ void CClient::OnSendCLProtMessage ( CHostAddress InetAddr,
Socket.SendPacket ( vecMessage, InetAddr );
}
void CClient::OnDetectedCLMessage ( CVector<uint8_t> vecbyData,
int iNumBytes )
{
// this is a special case: we received a connection less message but we are
// in a connection
ConnLessProtocol.ParseConnectionLessMessage ( vecbyData,
iNumBytes,
Channel.GetAddress() );
}
void CClient::OnNewConnection()
{
// a new connection was successfully initiated, send name and request
@ -420,6 +434,9 @@ void CClient::Stop()
// stop audio interface
Sound.Stop();
// disable channel
Channel.SetEnable ( false );
// wait for approx. 100 ms to make sure no audio packet is still in the
// network queue causing the channel to be reconnected right after having
// received the disconnect message (seems not to gain much, disconnect is
@ -440,10 +457,7 @@ void CClient::Stop()
// respond from the server, therefore we just hope that the message
// gets its way to the server, if not, the old behaviour time-out
// disconnects the connection anyway).
Channel.CreateAndImmSendDisconnectionMes();
// disable channel
Channel.SetEnable ( false );
ConnLessProtocol.CreateCLDisconnection ( Channel.GetAddress() );
// reset current signal level and LEDs
SignalLevelMeter.Reset();

View file

@ -318,6 +318,7 @@ protected:
public slots:
void OnSendProtMessage ( CVector<uint8_t> vecMessage );
void OnDetectedCLMessage ( CVector<uint8_t> vecbyData, int iNumBytes );
void OnReqJittBufSize() { Channel.CreateJitBufMes ( Channel.GetSockBufNumFrames() ); }
void OnReqChanName() { Channel.SetRemoteName ( strName ); }
void OnNewConnection();

View file

@ -140,11 +140,6 @@ MESSAGES (with connection)
note: does not have any data -> n = 0
- PROTMESSID_DISCONNECTION: Disconnect message
note: does not have any data -> n = 0
CONNECTION LESS MESSAGES
------------------------
@ -436,10 +431,9 @@ if ( rand() < ( RAND_MAX / 2 ) ) return false;
// in case this is a connection less message, we do not process it here
if ( IsConnectionLessMessageID ( iRecID ) )
{
// TODO fire signal so that an other class can process this type of message
// fire a signal so that an other class can process this type of
// message
emit DetectedCLMessage ( vecbyData, iNumBytes );
// return function without issuing an error code (since it is a
// regular message but will just not processed here)
@ -541,10 +535,6 @@ if ( rand() < ( RAND_MAX / 2 ) ) return false;
case PROTMESSID_REQ_NETW_TRANSPORT_PROPS:
bRet = EvaluateReqNetwTranspPropsMes();
break;
case PROTMESSID_DISCONNECTION:
bRet = EvaluateDisconnectionMes();
break;
}
// immediately send acknowledge message
@ -1108,37 +1098,6 @@ bool CProtocol::EvaluateReqNetwTranspPropsMes()
return false; // no error
}
void CProtocol::CreateAndImmSendDisconnectionMes()
{
CVector<uint8_t> vecDisconMessage;
int iCurCounter;
Mutex.lock();
{
// store current counter value
iCurCounter = iCounter;
// increase counter (wraps around automatically)
iCounter++;
}
Mutex.unlock();
// build complete message
GenMessageFrame ( vecDisconMessage, iCurCounter,
PROTMESSID_DISCONNECTION, CVector<uint8_t> ( 0 ) );
// immediately send acknowledge message
emit MessReadyForSending ( vecDisconMessage );
}
bool CProtocol::EvaluateDisconnectionMes()
{
// invoke message action
emit Disconnection();
return false; // no error
}
// Connection less messages ----------------------------------------------------
void CProtocol::CreateCLPingMes ( const CHostAddress& InetAddr, const int iMs )

View file

@ -50,7 +50,7 @@
#define PROTMESSID_PING_MS 19 // for measuring ping time
#define PROTMESSID_NETW_TRANSPORT_PROPS 20 // properties for network transport
#define PROTMESSID_REQ_NETW_TRANSPORT_PROPS 21 // request properties for network transport
#define PROTMESSID_DISCONNECTION 22 // disconnection
#define PROTMESSID_DISCONNECTION 22 // OLD (not used anymore)
#define PROTMESSID_REQ_CHANNEL_NAME 23 // request channel name for fader tag
// message IDs of connection less messages (CLM)
@ -123,8 +123,6 @@ 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 );
@ -209,7 +207,6 @@ protected:
bool EvaluatePingMes ( const CVector<uint8_t>& vecData );
bool EvaluateNetwTranspPropsMes ( const CVector<uint8_t>& vecData );
bool EvaluateReqNetwTranspPropsMes();
bool EvaluateDisconnectionMes();
bool EvaluateCLPingMes ( const CHostAddress& InetAddr,
const CVector<uint8_t>& vecData );
@ -258,9 +255,9 @@ signals:
void PingReceived ( int iMs );
void NetTranspPropsReceived ( CNetworkTransportProps NetworkTransportProps );
void ReqNetTranspProps();
void Disconnection();
void CLPingReceived ( CHostAddress InetAddr, int iMs );
void CLPingReceived ( CHostAddress InetAddr,
int iMs );
void CLPingWithNumClientsReceived ( CHostAddress InetAddr,
int iMs,
int iNumClients );
@ -272,6 +269,9 @@ signals:
void CLReqServerList ( CHostAddress InetAddr );
void CLSendEmptyMes ( CHostAddress TargetInetAddr );
void CLDisconnection ( CHostAddress InetAddr );
void DetectedCLMessage ( CVector<uint8_t> vecbyData,
int iNumBytes );
};
#endif /* !defined ( PROTOCOL_H__3B123453_4344_BB2392354455IUHF1912__INCLUDED_ ) */

View file

@ -325,6 +325,20 @@ CServer::CServer ( const int iNewNumChan,
QObject::connect ( &vecChannels[10], SIGNAL ( MessReadyForSending ( CVector<uint8_t> ) ), this, SLOT ( OnSendProtMessCh10 ( CVector<uint8_t> ) ) );
QObject::connect ( &vecChannels[11], SIGNAL ( MessReadyForSending ( CVector<uint8_t> ) ), this, SLOT ( OnSendProtMessCh11 ( CVector<uint8_t> ) ) );
// a connection less protocol message was detected
QObject::connect ( &vecChannels[0], SIGNAL ( DetectedCLMessage ( CVector<uint8_t>, int ) ), this, SLOT ( OnDetCLMessCh0 ( CVector<uint8_t>, int ) ) );
QObject::connect ( &vecChannels[1], SIGNAL ( DetectedCLMessage ( CVector<uint8_t>, int ) ), this, SLOT ( OnDetCLMessCh1 ( CVector<uint8_t>, int ) ) );
QObject::connect ( &vecChannels[2], SIGNAL ( DetectedCLMessage ( CVector<uint8_t>, int ) ), this, SLOT ( OnDetCLMessCh2 ( CVector<uint8_t>, int ) ) );
QObject::connect ( &vecChannels[3], SIGNAL ( DetectedCLMessage ( CVector<uint8_t>, int ) ), this, SLOT ( OnDetCLMessCh3 ( CVector<uint8_t>, int ) ) );
QObject::connect ( &vecChannels[4], SIGNAL ( DetectedCLMessage ( CVector<uint8_t>, int ) ), this, SLOT ( OnDetCLMessCh4 ( CVector<uint8_t>, int ) ) );
QObject::connect ( &vecChannels[5], SIGNAL ( DetectedCLMessage ( CVector<uint8_t>, int ) ), this, SLOT ( OnDetCLMessCh5 ( CVector<uint8_t>, int ) ) );
QObject::connect ( &vecChannels[6], SIGNAL ( DetectedCLMessage ( CVector<uint8_t>, int ) ), this, SLOT ( OnDetCLMessCh6 ( CVector<uint8_t>, int ) ) );
QObject::connect ( &vecChannels[7], SIGNAL ( DetectedCLMessage ( CVector<uint8_t>, int ) ), this, SLOT ( OnDetCLMessCh7 ( CVector<uint8_t>, int ) ) );
QObject::connect ( &vecChannels[8], SIGNAL ( DetectedCLMessage ( CVector<uint8_t>, int ) ), this, SLOT ( OnDetCLMessCh8 ( CVector<uint8_t>, int ) ) );
QObject::connect ( &vecChannels[9], SIGNAL ( DetectedCLMessage ( CVector<uint8_t>, int ) ), this, SLOT ( OnDetCLMessCh9 ( CVector<uint8_t>, int ) ) );
QObject::connect ( &vecChannels[10], SIGNAL ( DetectedCLMessage ( CVector<uint8_t>, int ) ), this, SLOT ( OnDetCLMessCh10 ( CVector<uint8_t>, int ) ) );
QObject::connect ( &vecChannels[11], SIGNAL ( DetectedCLMessage ( CVector<uint8_t>, int ) ), this, SLOT ( OnDetCLMessCh11 ( CVector<uint8_t>, int ) ) );
// request jitter buffer size
QObject::connect ( &vecChannels[0], SIGNAL ( NewConnection() ), this, SLOT ( OnNewConnectionCh0() ) );
QObject::connect ( &vecChannels[1], SIGNAL ( NewConnection() ), this, SLOT ( OnNewConnectionCh1() ) );
@ -411,6 +425,17 @@ void CServer::OnSendCLProtMessage ( CHostAddress InetAddr,
Socket.SendPacket ( vecMessage, InetAddr );
}
void CServer::OnDetCLMess ( const CVector<uint8_t>& vecbyData,
const int iNumBytes,
const CHostAddress& InetAddr )
{
// this is a special case: we received a connection less message but we are
// in a connection
ConnLessProtocol.ParseConnectionLessMessage ( vecbyData,
iNumBytes,
InetAddr );
}
void CServer::OnCLDisconnection ( CHostAddress InetAddr )
{
// check if the given address is actually a client which is connected to

View file

@ -245,6 +245,10 @@ public slots:
void OnSendProtMessage ( int iChID, CVector<uint8_t> vecMessage );
void OnSendCLProtMessage ( CHostAddress InetAddr, CVector<uint8_t> vecMessage );
void OnDetCLMess ( const CVector<uint8_t>& vecbyData,
const int iNumBytes,
const CHostAddress& InetAddr );
void OnCLPingReceived ( CHostAddress InetAddr, int iMs )
{
ConnLessProtocol.CreateCLPingWithNumClientsMes ( InetAddr,
@ -296,6 +300,19 @@ public slots:
void OnSendProtMessCh10 ( CVector<uint8_t> mess ) { OnSendProtMessage ( 10, mess ); }
void OnSendProtMessCh11 ( CVector<uint8_t> mess ) { OnSendProtMessage ( 11, mess ); }
void OnDetCLMessCh0 ( CVector<uint8_t> vData, int iNBy ) { OnDetCLMess ( vData, iNBy, vecChannels[0].GetAddress() ); }
void OnDetCLMessCh1 ( CVector<uint8_t> vData, int iNBy ) { OnDetCLMess ( vData, iNBy, vecChannels[1].GetAddress() ); }
void OnDetCLMessCh2 ( CVector<uint8_t> vData, int iNBy ) { OnDetCLMess ( vData, iNBy, vecChannels[2].GetAddress() ); }
void OnDetCLMessCh3 ( CVector<uint8_t> vData, int iNBy ) { OnDetCLMess ( vData, iNBy, vecChannels[3].GetAddress() ); }
void OnDetCLMessCh4 ( CVector<uint8_t> vData, int iNBy ) { OnDetCLMess ( vData, iNBy, vecChannels[4].GetAddress() ); }
void OnDetCLMessCh5 ( CVector<uint8_t> vData, int iNBy ) { OnDetCLMess ( vData, iNBy, vecChannels[5].GetAddress() ); }
void OnDetCLMessCh6 ( CVector<uint8_t> vData, int iNBy ) { OnDetCLMess ( vData, iNBy, vecChannels[6].GetAddress() ); }
void OnDetCLMessCh7 ( CVector<uint8_t> vData, int iNBy ) { OnDetCLMess ( vData, iNBy, vecChannels[7].GetAddress() ); }
void OnDetCLMessCh8 ( CVector<uint8_t> vData, int iNBy ) { OnDetCLMess ( vData, iNBy, vecChannels[8].GetAddress() ); }
void OnDetCLMessCh9 ( CVector<uint8_t> vData, int iNBy ) { OnDetCLMess ( vData, iNBy, vecChannels[9].GetAddress() ); }
void OnDetCLMessCh10 ( CVector<uint8_t> vData, int iNBy ) { OnDetCLMess ( vData, iNBy, vecChannels[10].GetAddress() ); }
void OnDetCLMessCh11 ( CVector<uint8_t> vData, int iNBy ) { OnDetCLMess ( vData, iNBy, vecChannels[11].GetAddress() ); }
void OnNewConnectionCh0() { vecChannels[0].CreateReqJitBufMes(); }
void OnNewConnectionCh1() { vecChannels[1].CreateReqJitBufMes(); }
void OnNewConnectionCh2() { vecChannels[2].CreateReqJitBufMes(); }

View file

@ -137,20 +137,7 @@ void CSocket::OnDataReceived()
// are not connected anymore
if ( pChannel->GetAddress() == RecHostAddr )
{
// 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 );
pConnLessProtocol->CreateCLDisconnection ( RecHostAddr );
}
}