Example #1
0
// Chiusura della connessione TCP in ricezione
void DuktoProtocol::closedConnection()
{
    // Svuoto il buffer in ricezione
    readNewData();

    // Chiusura eventuale file corrente
    if (mCurrentFile)
    {
        QString name;
        name = mCurrentFile->fileName();
        mCurrentFile->close();
        delete mCurrentFile;
        mCurrentFile = NULL;
        QFile::remove(name);
        receiveFileCancelled();
    }

    // Ricezione file conclusa
    else if (!mReceivingText)
        receiveFileComplete(mReceivedFiles);

    // Ricezione testo conclusa
    else
    {
        QString rec = QString::fromUtf8(mTextToReceive);
        receiveTextComplete(&rec);
    }

    // Chiusura socket
    if (mCurrentSocket)
    {
        mCurrentSocket->disconnect();
        mCurrentSocket->disconnectFromHost();
        mCurrentSocket->close();
        mCurrentSocket->deleteLater();
        mCurrentSocket = NULL;
    }

    // Rilascio memoria
    delete mReceivedFiles;
    mReceivedFiles = NULL;

    // Impostazione stato
    mIsReceiving = false;

}
Example #2
0
// Chiusura della connessione TCP in ricezione
void DuktoProtocol::closedConnection()
{
    // empty the receive buffer
    readNewData();

    // Closing any current file
    if (mCurrentFile)
    {
        QString name;
        name = mCurrentFile->fileName();
        mCurrentFile->close();
        delete mCurrentFile;
        mCurrentFile = NULL;
        QFile::remove(name);
        receiveFileCancelled();
    }
    else if (!mReceivingText) // Receiving file ended
    {
        receiveFileComplete(mReceivedFiles, mTotalSize);
        // TODO: notify for recieving file
    }
    else // Receiving text ended
    {
        QString rec = QString::fromUtf8(mTextToReceive);
        receiveTextComplete(&rec, mTotalSize);
        // TODO: notify for recieving text
    }

    // closing socket
    if (mCurrentSocket)
    {
        mCurrentSocket->disconnect();
        mCurrentSocket->disconnectFromHost();
        mCurrentSocket->close();
        mCurrentSocket->deleteLater();
        mCurrentSocket = NULL;
    }

    // release memory
    delete mReceivedFiles;
    mReceivedFiles = NULL;

    // reset status
    mIsReceiving = false;
}