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