mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-06 14:16:32 +02:00
* Prevent shutting down socket before all data has been read.
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
#include <QDebug>
|
||||
#include "bufferiodevice.h"
|
||||
|
||||
|
||||
BufferIODevice::BufferIODevice( unsigned int size, QObject *parent ) :
|
||||
QIODevice( parent ),
|
||||
m_size( size ),
|
||||
@@ -27,7 +28,6 @@ BufferIODevice::close()
|
||||
|
||||
qDebug() << Q_FUNC_INFO;
|
||||
QIODevice::close();
|
||||
// TODO ?
|
||||
}
|
||||
|
||||
|
||||
@@ -39,6 +39,7 @@ BufferIODevice::inputComplete( const QString& errmsg )
|
||||
emit readChannelFinished();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
BufferIODevice::addData( QByteArray ba )
|
||||
{
|
||||
@@ -58,9 +59,7 @@ qint64
|
||||
BufferIODevice::readData( char * data, qint64 maxSize )
|
||||
{
|
||||
//qDebug() << Q_FUNC_INFO << maxSize;
|
||||
|
||||
QMutexLocker lock( &m_mut );
|
||||
// qDebug() << "readData begins, bufersize:" << m_buffer.length();
|
||||
|
||||
qint64 size = maxSize;
|
||||
if ( m_buffer.length() < maxSize )
|
||||
@@ -93,13 +92,14 @@ qint64 BufferIODevice::size() const
|
||||
return m_size;
|
||||
}
|
||||
|
||||
|
||||
bool BufferIODevice::atEnd() const
|
||||
{
|
||||
QMutexLocker lock( &m_mut );
|
||||
return m_size == m_received &&
|
||||
m_buffer.length() == 0;
|
||||
return ( m_size == m_received && m_buffer.length() == 0 );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
BufferIODevice::clear()
|
||||
{
|
||||
|
@@ -21,7 +21,6 @@ public:
|
||||
void addData( QByteArray ba );
|
||||
void clear();
|
||||
|
||||
bool isOpen() const { qDebug() << "isOpen"; return true; }
|
||||
OpenMode openMode() const { qDebug() << "openMode"; return QIODevice::ReadWrite; }
|
||||
|
||||
void inputComplete( const QString& errmsg = "" );
|
||||
|
@@ -266,9 +266,16 @@ Connection::socketDisconnected()
|
||||
void
|
||||
Connection::socketDisconnectedError(QAbstractSocket::SocketError e)
|
||||
{
|
||||
if ( e == QAbstractSocket::RemoteHostClosedError )
|
||||
return;
|
||||
|
||||
qDebug() << "SOCKET ERROR CODE" << e << this->name() << "CALLING Connection::shutdown(false)";
|
||||
|
||||
m_peer_disconnected = true;
|
||||
|
||||
emit socketErrored(e);
|
||||
emit socketClosed();
|
||||
|
||||
shutdown( false );
|
||||
}
|
||||
|
||||
|
@@ -16,8 +16,7 @@
|
||||
using namespace Tomahawk;
|
||||
|
||||
|
||||
FileTransferConnection::FileTransferConnection( Servent* s, ControlConnection* cc,
|
||||
QString fid, unsigned int size )
|
||||
FileTransferConnection::FileTransferConnection( Servent* s, ControlConnection* cc, QString fid, unsigned int size )
|
||||
: Connection( s )
|
||||
, m_cc( cc )
|
||||
, m_fid( fid )
|
||||
@@ -27,6 +26,7 @@ FileTransferConnection::FileTransferConnection( Servent* s, ControlConnection* c
|
||||
, m_allok( false )
|
||||
{
|
||||
qDebug() << Q_FUNC_INFO;
|
||||
|
||||
BufferIODevice* bio = new BufferIODevice( size );
|
||||
m_iodev = QSharedPointer<QIODevice>( bio ); // device audio data gets written to
|
||||
m_iodev->open( QIODevice::ReadWrite );
|
||||
@@ -47,7 +47,12 @@ FileTransferConnection::FileTransferConnection( Servent* s, ControlConnection* c
|
||||
|
||||
|
||||
FileTransferConnection::FileTransferConnection( Servent* s, QString fid )
|
||||
: Connection(s), m_fid(fid), m_type(SENDING), m_badded(0), m_bsent(0), m_allok( false )
|
||||
: Connection( s )
|
||||
, m_fid( fid )
|
||||
, m_type( SENDING )
|
||||
, m_badded( 0 )
|
||||
, m_bsent( 0 )
|
||||
, m_allok( false )
|
||||
{
|
||||
APP->servent().registerFileTransferConnection( this );
|
||||
// auto delete when connection closes:
|
||||
@@ -65,7 +70,10 @@ FileTransferConnection::~FileTransferConnection()
|
||||
|
||||
// protected, we could expose it:
|
||||
//m_iodev->setErrorString("FTConnection providing data went away mid-transfer");
|
||||
|
||||
((BufferIODevice*)m_iodev.data())->inputComplete();
|
||||
}
|
||||
|
||||
APP->servent().fileTransferFinished( this );
|
||||
}
|
||||
|
||||
@@ -104,7 +112,7 @@ FileTransferConnection::setup()
|
||||
qDebug() << "in TX mode, fid:" << m_fid;
|
||||
|
||||
DatabaseCommand_LoadFile* cmd = new DatabaseCommand_LoadFile( m_fid );
|
||||
connect(cmd, SIGNAL(result(QVariantMap)), this, SLOT(startSending(QVariantMap)));
|
||||
connect( cmd, SIGNAL( result( QVariantMap ) ), SLOT( startSending( QVariantMap ) ) );
|
||||
TomahawkApp::instance()->database()->enqueue( QSharedPointer<DatabaseCommand>( cmd ) );
|
||||
}
|
||||
|
||||
@@ -139,13 +147,11 @@ FileTransferConnection::handleMsg( msg_ptr msg )
|
||||
// << "payload len" << msg->payload().length()
|
||||
// << "written to device so far: " << m_badded;
|
||||
|
||||
|
||||
if( !msg->is( Msg::FRAGMENT ) )
|
||||
{
|
||||
qDebug() << endl
|
||||
<< "*** Got last msg in filetransfer. added" << m_badded
|
||||
<< "io size" << m_iodev->size()
|
||||
<< endl;
|
||||
qDebug() << "*** Got last msg in filetransfer. added" << m_badded
|
||||
<< "io size" << m_iodev->size();
|
||||
|
||||
m_allok = true;
|
||||
// tell our iodev there is no more data to read, no args meaning a success:
|
||||
((BufferIODevice*)m_iodev.data())->inputComplete();
|
||||
@@ -156,7 +162,8 @@ FileTransferConnection::handleMsg( msg_ptr msg )
|
||||
|
||||
Connection* FileTransferConnection::clone()
|
||||
{
|
||||
Q_ASSERT(false); return 0;
|
||||
Q_ASSERT( false );
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
@@ -32,10 +32,7 @@ public:
|
||||
void setup();
|
||||
Connection* clone();
|
||||
|
||||
const QSharedPointer<QIODevice>& iodevice()
|
||||
{
|
||||
return m_iodev;
|
||||
}
|
||||
const QSharedPointer<QIODevice>& iodevice() { return m_iodev; }
|
||||
|
||||
Type type() const { return m_type; }
|
||||
QString fid() const { return m_fid; }
|
||||
|
Reference in New Issue
Block a user