diff --git a/src/client.cpp b/src/client.cpp index 6c874b11..52a7760b 100755 --- a/src/client.cpp +++ b/src/client.cpp @@ -133,7 +133,7 @@ CClient::CClient ( const quint16 iPortNumber ) : // Connections ------------------------------------------------------------- - // connection for protocol + // connections for the protocol mechanism QObject::connect ( &Channel, SIGNAL ( MessReadyForSending ( CVector ) ), this, SLOT ( OnSendProtMessage ( CVector ) ) ); @@ -192,8 +192,13 @@ QObject::connect ( &Channel, SIGNAL ( OpusSupported() ), SIGNAL ( CLPingWithNumClientsReceived ( CHostAddress, int, int ) ), this, SLOT ( OnCLPingWithNumClientsReceived ( CHostAddress, int, int ) ) ); + + // other QObject::connect ( &Sound, SIGNAL ( ReinitRequest ( int ) ), this, SLOT ( OnSndCrdReinitRequest ( int ) ) ); + + QObject::connect ( &Socket, SIGNAL ( InvalidPacketReceived ( CVector, int, CHostAddress ) ), + this, SLOT ( OnInvalidPacketReceived ( CVector, int, CHostAddress ) ) ); } void CClient::OnSendProtMessage ( CVector vecMessage ) @@ -211,6 +216,30 @@ void CClient::OnSendCLProtMessage ( CHostAddress InetAddr, Socket.SendPacket ( vecMessage, InetAddr ); } +void CClient::OnInvalidPacketReceived ( CVector vecbyRecBuf, + int iNumBytesRead, + CHostAddress RecHostAddr ) +{ + // this is an unknown address or we are not connected, try to + // parse connection less message (we have this case when we, + // e.g., open the connection setup dialog since then we are not + // yet connected but talk to the central server with the + // connection less protocol) + if ( ConnLessProtocol.ParseConnectionLessMessage ( vecbyRecBuf, + iNumBytesRead, + RecHostAddr ) ) + { + // message coult not be parsed, check if the packet comes + // from the server we just connected -> if yes, send + // disconnect message since the server may not know that we + // are not connected anymore + if ( Channel. GetAddress() == RecHostAddr ) + { + ConnLessProtocol.CreateCLDisconnection ( RecHostAddr ); + } + } +} + void CClient::OnDetectedCLMessage ( CVector vecbyData, int iNumBytes ) { diff --git a/src/client.h b/src/client.h index 2d65ef37..9e97b562 100755 --- a/src/client.h +++ b/src/client.h @@ -347,6 +347,9 @@ void SetAudoCompressiontype ( const EAudComprType eNAudCompressionType ); public slots: void OnSendProtMessage ( CVector vecMessage ); + void OnInvalidPacketReceived ( CVector vecbyRecBuf, + int iNumBytesRead, + CHostAddress RecHostAddr ); void OnDetectedCLMessage ( CVector vecbyData, int iNumBytes ); void OnReqJittBufSize() { CreateServerJitterBufferMessage(); } void OnJittBufSizeChanged ( int iNewJitBufSize ); diff --git a/src/socket.cpp b/src/socket.cpp index eed0fa7e..b95acd35 100755 --- a/src/socket.cpp +++ b/src/socket.cpp @@ -121,57 +121,45 @@ void CSocket::OnDataReceived() if ( bIsClient ) { // client: + // check if packet comes from the server we want to connect and that // the channel is enabled - if ( !( pChannel->GetAddress() == RecHostAddr ) || - !pChannel->IsEnabled() ) + if ( ( pChannel->GetAddress() == RecHostAddr ) && + pChannel->IsEnabled() ) { - // this is an unknown address or we are not connected, try to - // parse connection less message (we have this case when we, - // e.g., open the connection setup dialog since then we are not - // yet connected but talk to the central server with the - // connection less protocol) - if ( pConnLessProtocol->ParseConnectionLessMessage ( vecbyRecBuf, - iNumBytesRead, - RecHostAddr ) ) + // this network packet is valid, put it in the channel + switch ( pChannel->PutData ( vecbyRecBuf, iNumBytesRead ) ) { - // message coult not be parsed, check if the packet comes - // from the server we just connected -> if yes, send - // disconnect message since the server may not know that we - // are not connected anymore - if ( pChannel->GetAddress() == RecHostAddr ) - { - pConnLessProtocol->CreateCLDisconnection ( RecHostAddr ); - } + case PS_AUDIO_OK: + PostWinMessage ( MS_JIT_BUF_PUT, MUL_COL_LED_GREEN ); + break; + + case PS_AUDIO_ERR: + case PS_GEN_ERROR: + PostWinMessage ( MS_JIT_BUF_PUT, MUL_COL_LED_RED ); + break; + + case PS_PROT_ERR: + PostWinMessage ( MS_JIT_BUF_PUT, MUL_COL_LED_YELLOW ); + break; + + default: + // other put data states need not to be considered here + break; } - - // do not perform any other action on this received packet - return; } - - switch ( pChannel->PutData ( vecbyRecBuf, iNumBytesRead ) ) + else { - case PS_AUDIO_OK: - PostWinMessage ( MS_JIT_BUF_PUT, MUL_COL_LED_GREEN ); - break; - - case PS_AUDIO_ERR: - case PS_GEN_ERROR: - PostWinMessage ( MS_JIT_BUF_PUT, MUL_COL_LED_RED ); - break; - - case PS_PROT_ERR: - PostWinMessage ( MS_JIT_BUF_PUT, MUL_COL_LED_YELLOW ); - break; - - default: - // other put data states need not to be considered here - break; + // inform about received invalid packet by fireing an event + emit InvalidPacketReceived ( vecbyRecBuf, + iNumBytesRead, + RecHostAddr ); } } else { // server: + if ( pServer->PutData ( vecbyRecBuf, iNumBytesRead, RecHostAddr ) ) { // this was an audio packet, start server diff --git a/src/socket.h b/src/socket.h index b1f00b39..95d505ff 100755 --- a/src/socket.h +++ b/src/socket.h @@ -29,6 +29,7 @@ #include #include #include +#include #include #include #include "global.h" @@ -48,6 +49,7 @@ class CServer; // forward declaration of CServer /* Classes ********************************************************************/ +/* Base socket class ---------------------------------------------------------*/ class CSocket : public QObject { Q_OBJECT @@ -83,6 +85,50 @@ protected: public slots: void OnDataReceived(); + +signals: + void InvalidPacketReceived ( CVector vecbyRecBuf, + int iNumBytesRead, + CHostAddress RecHostAddr ); }; + +/* Socket which runs in a separate high priority thread ----------------------*/ + +/* +// TEST + +// http://qt-project.org/forums/viewthread/14393 +// http://qt-project.org/doc/qt-5.0/qtcore/qthread.html#Priority-enum +// http://qt-project.org/wiki/Threads_Events_QObjects + +class CHighPrioSocket +{ +public: + CHighPrioSocket ( CChannel* pNewChannel, + CProtocol* pNewCLProtocol, + const quint16 iPortNumber ) + { + + // TEST + worker = new CSocket ( pNewChannel, pNewCLProtocol, iPortNumber ); + worker->moveToThread(&workerThread); + workerThread.start(QThread::TimeCriticalPriority); + + } + + void SendPacket ( const CVector& vecbySendBuf, + const CHostAddress& HostAddr ) + { + worker->SendPacket ( vecbySendBuf, HostAddr ); + } + +protected: + + // TEST + QThread workerThread; + CSocket* worker; +}; +*/ + #endif /* !defined ( SOCKET_HOIHGE76GEKJH98_3_4344_BB23945IUHF1912__INCLUDED_ ) */