mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-05 13:47:26 +02:00
Make QNR_IODeviceStream thread-safe
This commit is contained in:
@@ -74,15 +74,13 @@ QNR_IODeviceStream::QNR_IODeviceStream( const QSharedPointer<QNetworkReply>& rep
|
||||
|
||||
QNR_IODeviceStream::~QNR_IODeviceStream()
|
||||
{
|
||||
tDebug() << Q_FUNC_INFO;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
QNR_IODeviceStream::seekStream( qint64 offset )
|
||||
{
|
||||
tDebug() << Q_FUNC_INFO;
|
||||
|
||||
QMutexLocker locker( &m_mutex );
|
||||
m_pos = offset;
|
||||
}
|
||||
|
||||
@@ -90,6 +88,7 @@ QNR_IODeviceStream::seekStream( qint64 offset )
|
||||
qint64
|
||||
QNR_IODeviceStream::needData ( void** buffer )
|
||||
{
|
||||
QMutexLocker locker( &m_mutex );
|
||||
QByteArray data = m_data.mid( m_pos, BLOCK_SIZE );
|
||||
m_pos += data.size();
|
||||
if ( ( data.size() == 0 ) && m_networkReply->atEnd() && m_networkReply->isFinished() )
|
||||
@@ -101,13 +100,13 @@ QNR_IODeviceStream::needData ( void** buffer )
|
||||
|
||||
*buffer = new char[data.size()];
|
||||
memcpy(*buffer, data.data(), data.size());
|
||||
// tDebug() << Q_FUNC_INFO << " Returning buffer with size " << data.size();
|
||||
return data.size();
|
||||
}
|
||||
|
||||
void
|
||||
QNR_IODeviceStream::readyRead()
|
||||
{
|
||||
QMutexLocker locker( &m_mutex );
|
||||
m_data += m_networkReply->readAll();
|
||||
}
|
||||
|
||||
|
@@ -26,6 +26,7 @@
|
||||
#include "DllMacro.h"
|
||||
|
||||
#include <QByteArray>
|
||||
#include <QMutex>
|
||||
#include <QNetworkReply>
|
||||
#include <QSharedPointer>
|
||||
|
||||
@@ -52,6 +53,7 @@ private slots:
|
||||
void readyRead();
|
||||
|
||||
private:
|
||||
QMutex m_mutex;
|
||||
QByteArray m_data;
|
||||
QSharedPointer<QNetworkReply> m_networkReply;
|
||||
QTimer* m_timer;
|
||||
|
Reference in New Issue
Block a user