Permalink
Browse files

Refs #10311. Convert FileTransfer reference counting to ReferenceCoun…

…ter.
  • Loading branch information...
daniel-kristjansson committed Jun 1, 2012
1 parent ad6d965 commit cd996fdc97bcf8bea05096ba6b99ff5355c4349e
@@ -11,21 +11,23 @@
FileTransfer::FileTransfer(QString &filename, MythSocket *remote,
bool usereadahead, int timeout_ms) :
ReferenceCounter(QString("FileTransfer:%1").arg(filename)),
readthreadlive(true), readsLocked(false),
rbuffer(RingBuffer::Create(filename, false, usereadahead, timeout_ms, true)),
sock(remote), ateof(false), lock(QMutex::NonRecursive),
refLock(QMutex::NonRecursive), refCount(0), writemode(false)
writemode(false)
{
pginfo = new ProgramInfo(filename);
pginfo->MarkAsInUse(true, kFileTransferInUseID);
rbuffer->Start();
}
FileTransfer::FileTransfer(QString &filename, MythSocket *remote, bool write) :
ReferenceCounter(QString("FileTransfer:%1").arg(filename)),
readthreadlive(true), readsLocked(false),
rbuffer(RingBuffer::Create(filename, write)),
sock(remote), ateof(false), lock(QMutex::NonRecursive),
refLock(QMutex::NonRecursive), refCount(0), writemode(write)
writemode(write)
{
pginfo = new ProgramInfo(filename);
pginfo->MarkAsInUse(true, kFileTransferInUseID);
@@ -52,26 +54,6 @@ FileTransfer::~FileTransfer()
}
}
void FileTransfer::UpRef(void)
{
QMutexLocker locker(&refLock);
refCount++;
}
bool FileTransfer::DownRef(void)
{
int count = 0;
{
QMutexLocker locker(&refLock);
count = --refCount;
}
if (count < 0)
delete this;
return (count < 0);
}
bool FileTransfer::isOpen(void)
{
if (rbuffer && rbuffer->IsOpen())
@@ -12,12 +12,15 @@ using namespace std;
#include <QMutex>
#include <QWaitCondition>
// MythTV headers
#include "referencecounter.h"
class ProgramInfo;
class RingBuffer;
class MythSocket;
class QString;
class FileTransfer
class FileTransfer : public ReferenceCounter
{
friend class QObject; // quiet OSX gcc warning
@@ -33,9 +36,6 @@ class FileTransfer
void Stop(void);
void UpRef(void);
bool DownRef(void);
void Pause(void);
void Unpause(void);
int RequestBlock(int size);
@@ -1571,16 +1571,20 @@ void MainServer::HandleAnnounce(QStringList &slist, QStringList commands,
ft = new FileTransfer(filename, socket, writemode);
}
else
{
ft = new FileTransfer(filename, socket, usereadahead, timeout_ms);
}
ft->IncrRef();
sockListLock.lockForWrite();
fileTransferList.push_back(ft);
sockListLock.unlock();
retlist << QString::number(socket->socket());
ft->UpRef();
retlist << QString::number(ft->GetFileSize());
ft->DownRef();
ft->DecrRef();
if (checkfiles.size())
{
@@ -5023,7 +5027,7 @@ void MainServer::HandleFileTransferQuery(QStringList &slist,
return;
}
ft->UpRef();
ft->IncrRef();
sockListLock.unlock();
if (command == "IS_OPEN")
@@ -5074,7 +5078,7 @@ void MainServer::HandleFileTransferQuery(QStringList &slist,
retlist << "ok";
}
ft->DownRef();
ft->DecrRef();
SendResponse(pbssock, retlist);
}
@@ -5775,7 +5779,7 @@ void MainServer::connectionClosed(MythSocket *socket)
MythSocket *sock = (*ft)->getSocket();
if (sock == socket)
{
(*ft)->DownRef();
(*ft)->DecrRef();
fileTransferList.erase(ft);
sockListLock.unlock();
return;

0 comments on commit cd996fd

Please sign in to comment.