Do a test where we use waitforreadyread instead of event driven -> this seems to solve the thread priority issue with the GUI but we get a crash in the Socket (mutex/thread-save issue).
This commit is contained in:
parent
76d8de72b6
commit
2ad0890bf2
2 changed files with 40 additions and 2 deletions
|
@ -74,6 +74,8 @@ void CSocket::Init ( const quint16 iPortNumber )
|
|||
#ifdef ENABLE_RECEIVE_SOCKET_IN_SEPARATE_THREAD
|
||||
if ( bIsClient )
|
||||
{
|
||||
// TEST We do a test where we call "waitForReadyRead" instead of even driven method.
|
||||
/*
|
||||
// We have to use a blocked queued connection since in case we use a
|
||||
// separate socket thread, the "readyRead" signal would occur and our
|
||||
// "OnDataReceived" function would be run in another thread. This could
|
||||
|
@ -82,6 +84,7 @@ void CSocket::Init ( const quint16 iPortNumber )
|
|||
// socket notifiers for same socket" may occur.
|
||||
QObject::connect ( &SocketDevice, SIGNAL ( readyRead() ),
|
||||
this, SLOT ( OnDataReceived() ), Qt::BlockingQueuedConnection );
|
||||
*/
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
39
src/socket.h
39
src/socket.h
|
@ -72,6 +72,11 @@ public:
|
|||
|
||||
bool GetAndResetbJitterBufferOKFlag();
|
||||
|
||||
#ifdef ENABLE_RECEIVE_SOCKET_IN_SEPARATE_THREAD
|
||||
// TEST
|
||||
void waitForReadyRead() { SocketDevice.waitForReadyRead(); }
|
||||
#endif
|
||||
|
||||
protected:
|
||||
void Init ( const quint16 iPortNumber = LLCON_DEFAULT_PORT_NUMBER );
|
||||
|
||||
|
@ -117,6 +122,9 @@ public:
|
|||
// http://qt-project.org/wiki/Threads_Events_QObjects
|
||||
pSocket = new CSocket ( pNewChannel, iPortNumber );
|
||||
pSocket->moveToThread ( &NetworkWorkerThread );
|
||||
|
||||
NetworkWorkerThread.SetSocket ( pSocket );
|
||||
|
||||
NetworkWorkerThread.start ( QThread::TimeCriticalPriority );
|
||||
|
||||
// connect the "InvalidPacketReceived" signal
|
||||
|
@ -142,8 +150,35 @@ public:
|
|||
}
|
||||
|
||||
protected:
|
||||
QThread NetworkWorkerThread;
|
||||
CSocket* pSocket;
|
||||
class CSocketThread : public QThread
|
||||
{
|
||||
public:
|
||||
CSocketThread ( CSocket* pNewSocket = NULL, QObject* parent = 0 ) :
|
||||
pSocket ( pNewSocket ), QThread ( parent ), bRun ( true ) {}
|
||||
|
||||
void SetSocket ( CSocket* pNewSocket ) { pSocket = pNewSocket; }
|
||||
void Stop() { bRun = false;
|
||||
// TODO wait for thread to be deleted...
|
||||
}
|
||||
|
||||
protected:
|
||||
void run() {
|
||||
if ( pSocket != NULL )
|
||||
{
|
||||
while ( bRun )
|
||||
{
|
||||
pSocket->waitForReadyRead();
|
||||
pSocket->OnDataReceived();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
CSocket* pSocket;
|
||||
bool bRun;
|
||||
};
|
||||
|
||||
CSocketThread NetworkWorkerThread;
|
||||
CSocket* pSocket;
|
||||
|
||||
signals:
|
||||
void InvalidPacketReceived ( CVector<uint8_t> vecbyRecBuf,
|
||||
|
|
Loading…
Reference in a new issue