clean up the socket so that we do not have direct calls to e.g. protocol messages
This commit is contained in:
parent
21707b0e17
commit
8e95b548cb
4 changed files with 106 additions and 40 deletions
|
@ -133,7 +133,7 @@ CClient::CClient ( const quint16 iPortNumber ) :
|
|||
|
||||
|
||||
// Connections -------------------------------------------------------------
|
||||
// connection for protocol
|
||||
// connections for the protocol mechanism
|
||||
QObject::connect ( &Channel,
|
||||
SIGNAL ( MessReadyForSending ( CVector<uint8_t> ) ),
|
||||
this, SLOT ( OnSendProtMessage ( CVector<uint8_t> ) ) );
|
||||
|
@ -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<uint8_t>, int, CHostAddress ) ),
|
||||
this, SLOT ( OnInvalidPacketReceived ( CVector<uint8_t>, int, CHostAddress ) ) );
|
||||
}
|
||||
|
||||
void CClient::OnSendProtMessage ( CVector<uint8_t> vecMessage )
|
||||
|
@ -211,6 +216,30 @@ void CClient::OnSendCLProtMessage ( CHostAddress InetAddr,
|
|||
Socket.SendPacket ( vecMessage, InetAddr );
|
||||
}
|
||||
|
||||
void CClient::OnInvalidPacketReceived ( CVector<uint8_t> 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<uint8_t> vecbyData,
|
||||
int iNumBytes )
|
||||
{
|
||||
|
|
|
@ -347,6 +347,9 @@ void SetAudoCompressiontype ( const EAudComprType eNAudCompressionType );
|
|||
|
||||
public slots:
|
||||
void OnSendProtMessage ( CVector<uint8_t> vecMessage );
|
||||
void OnInvalidPacketReceived ( CVector<uint8_t> vecbyRecBuf,
|
||||
int iNumBytesRead,
|
||||
CHostAddress RecHostAddr );
|
||||
void OnDetectedCLMessage ( CVector<uint8_t> vecbyData, int iNumBytes );
|
||||
void OnReqJittBufSize() { CreateServerJitterBufferMessage(); }
|
||||
void OnJittBufSizeChanged ( int iNewJitBufSize );
|
||||
|
|
|
@ -121,34 +121,13 @@ 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 ) )
|
||||
{
|
||||
// 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 );
|
||||
}
|
||||
}
|
||||
|
||||
// do not perform any other action on this received packet
|
||||
return;
|
||||
}
|
||||
|
||||
// this network packet is valid, put it in the channel
|
||||
switch ( pChannel->PutData ( vecbyRecBuf, iNumBytesRead ) )
|
||||
{
|
||||
case PS_AUDIO_OK:
|
||||
|
@ -170,8 +149,17 @@ void CSocket::OnDataReceived()
|
|||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// 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
|
||||
|
|
46
src/socket.h
46
src/socket.h
|
@ -29,6 +29,7 @@
|
|||
#include <QMessageBox>
|
||||
#include <QUdpSocket>
|
||||
#include <QSocketNotifier>
|
||||
#include <QThread>
|
||||
#include <QMutex>
|
||||
#include <vector>
|
||||
#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<uint8_t> 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<uint8_t>& vecbySendBuf,
|
||||
const CHostAddress& HostAddr )
|
||||
{
|
||||
worker->SendPacket ( vecbySendBuf, HostAddr );
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
// TEST
|
||||
QThread workerThread;
|
||||
CSocket* worker;
|
||||
};
|
||||
*/
|
||||
|
||||
#endif /* !defined ( SOCKET_HOIHGE76GEKJH98_3_4344_BB23945IUHF1912__INCLUDED_ ) */
|
||||
|
|
Loading…
Reference in a new issue