diff --git a/src/socket.cpp b/src/socket.cpp index 2ffe451c..becb8b68 100755 --- a/src/socket.cpp +++ b/src/socket.cpp @@ -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 { diff --git a/src/socket.h b/src/socket.h index 12952651..73c94893 100755 --- a/src/socket.h +++ b/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 vecbyRecBuf,