コード例 #1
0
bool QIODeviceProto::waitForReadyRead(int msecs)
{
  QIODevice *item = qscriptvalue_cast<QIODevice*>(thisObject());
  if (item)
    return item->waitForReadyRead(msecs);
  return false;
}
コード例 #2
0
ファイル: rkgraphicsdevice_stubs.cpp プロジェクト: KDE/rkward
	RKGraphicsDataStreamReadGuard () {
		RKGraphicsDeviceBackendTransmitter::mutex.lock ();
		have_lock = true;
		rkd_waiting_for_reply = true;
		QIODevice* connection = RKGraphicsDeviceBackendTransmitter::connection;
		BEGIN_SUSPEND_INTERRUPTS {
			while (connection->bytesToWrite ()) {
				if (!connection->waitForBytesWritten (10)) {
					checkHandleError ();
				}
				if (connection->bytesToWrite ()) RKREventLoop::processX11Events ();
			}
			while (!RKGraphicsDeviceBackendTransmitter::streamer.readInBuffer ()) {
				RKREventLoop::processX11Events ();
				if (!connection->waitForReadyRead (10)) {
					if (checkHandleInterrupt (connection)) break;
					checkHandleError ();
				}
			}
			if (R_interrupts_pending) {
				if (have_lock) {
					RKGraphicsDeviceBackendTransmitter::mutex.unlock ();
					have_lock = false;  // Will d'tor still be called? We don't rely on it.
				}
				rkd_waiting_for_reply = false;
			}
		} END_SUSPEND_INTERRUPTS;
	}
コード例 #3
0
void KoImageDataPrivate::copyToTemporary(QIODevice &device)
{
    delete temporaryFile;
    temporaryFile = new KTemporaryFile();
    temporaryFile->setPrefix("KoImageData");
    if (!temporaryFile->open()) {
        kWarning(30006) << "open temporary file for writing failed";
        errorCode = KoImageData::StorageFailed;
        return;
    }
    QCryptographicHash md5(QCryptographicHash::Md5);
    char buf[8096];
    while (true) {
        device.waitForReadyRead(-1);
        qint64 bytes = device.read(buf, sizeof(buf));
        if (bytes <= 0)
            break; // done!
        md5.addData(buf, bytes);
        do {
            bytes -= temporaryFile->write(buf, bytes);
        } while (bytes > 0);
    }
    key = KoImageDataPrivate::generateKey(md5.result());

    temporaryFile->close();

    //QFileInfo fi(*temporaryFile);
    dataStoreState = StateNotLoaded;
}
コード例 #4
0
ファイル: KoImageData_p.cpp プロジェクト: AninaRJ/krita
void KoImageDataPrivate::copyToTemporary(QIODevice &device)
{
    delete temporaryFile;
    temporaryFile = new QTemporaryFile(QDir::tempPath() + "/" + qAppName() + QLatin1String("_XXXXXX"));
    if (!temporaryFile->open()) {
        warnFlake << "open temporary file for writing failed";
        errorCode = KoImageData::StorageFailed;
        return;
    }
    QCryptographicHash md5(QCryptographicHash::Md5);
    char buf[8096];
    while (true) {
        device.waitForReadyRead(-1);
        qint64 bytes = device.read(buf, sizeof(buf));
        if (bytes <= 0)
            break; // done!
        md5.addData(buf, bytes);
        do {
            bytes -= temporaryFile->write(buf, bytes);
        } while (bytes > 0);
    }
    key = KoImageDataPrivate::generateKey(md5.result());

    temporaryFile->close();

    dataStoreState = StateNotLoaded;
}
コード例 #5
0
ファイル: packet.cpp プロジェクト: xobs/sd-capture
static qint64 streamReadData(QIODevice &source, char *data, qint64 bytesTotal) {
	qint64 bytesRead = 0;
	qint64 bytesLeft = bytesTotal;
	int result;

	while (bytesLeft > 0) {
		result = source.read(data, bytesLeft);
		if (result < 0) {
			qDebug() << "Source had error:" << source.errorString();
			return result;
		}

		if (result == 0) {
			if (!source.waitForReadyRead(-1)) {
				qDebug() << "Source is done, closing";
				break;
			}
		}

		if (result > bytesTotal) {
			qDebug() << "Very bad.  Wanted " << bytesTotal << ", but got " << result;
		}
		bytesRead += result;
		data += result;
		if (bytesLeft - result < 0) {
			qDebug() << "That was a really strange read";
		}
		bytesLeft -= result;
	}
	if (bytesLeft < 0) {
		qDebug() << "How could bytesLeft (" << bytesLeft << ") be less than zero?";
	}
	return bytesRead;
}
コード例 #6
0
ファイル: VideoData.cpp プロジェクト: abhishekmurthy/Calligra
void VideoData::copyToTemporary(QIODevice &device)
{
    delete d;
    d = new VideoDataPrivate();
    d->temporaryFile = new KTemporaryFile();
    d->refCount.ref();
    d->temporaryFile->setPrefix("KoVideoData");
    if (!d->temporaryFile->open()) {
        kWarning(30006) << "open temporary file for writing failed";
        d->errorCode = VideoData::StorageFailed;
        delete d;
        d = 0;
        return;
    }
    QCryptographicHash md5(QCryptographicHash::Md5);
    char buf[8192];
    while (true) {
        device.waitForReadyRead(-1);
        qint64 bytes = device.read(buf, sizeof(buf));
        if (bytes <= 0)
            break; // done!
        md5.addData(buf, bytes);
        do {
            bytes -= d->temporaryFile->write(buf, bytes);
        } while (bytes > 0);
    }
    d->key = VideoData::generateKey(md5.result());
    d->temporaryFile->close();

    QFileInfo fi(*(d->temporaryFile));
    d->dataStoreState = StateSpooled;
}
コード例 #7
0
ファイル: rkcommand.cpp プロジェクト: atikbif/relkonIDE
bool RkCommand::waitAnAnswer(Request &req, QIODevice &io)
{
    if(io.isOpen()){
        QByteArray answer;
        if(io.waitForReadyRead(100)){
            int cnt=0;
            answer+=io.readAll();
            while(io.waitForReadyRead(10)) {
                answer+=io.readAll();
                cnt++;if(cnt>=maxCnt) break;
            }
        }
        req.updateRdData(answer);
        if(answer.count()) {return true;}
    }
    return false;
}
コード例 #8
0
ファイル: tst_qiodevice.cpp プロジェクト: KDE/android-qt
//----------------------------------------------------------------------------------
void tst_QIODevice::constructing_QTcpSocket()
{
#if defined(Q_OS_WINCE) && defined(WINCE_EMULATOR_TEST)
    QSKIP("Networking tests in a WinCE emulator are unstable", SkipAll);
#endif
    QTcpSocket socket;
    QIODevice *device = &socket;

    QVERIFY(!device->isOpen());

    socket.connectToHost(QtNetworkSettings::serverName(), 143);
    QVERIFY(socket.waitForConnected(5000));
    QVERIFY(device->isOpen());

    while (!device->canReadLine())
        QVERIFY(device->waitForReadyRead(5000));

    char buf[1024];
    memset(buf, 0, sizeof(buf));
    qlonglong lineLength = device->readLine(buf, sizeof(buf));
    QVERIFY(lineLength > 0);
    QCOMPARE(socket.pos(), qlonglong(0));

    socket.close();
    socket.connectToHost(QtNetworkSettings::serverName(), 143);
    QVERIFY(socket.waitForConnected(5000));
    QVERIFY(device->isOpen());

    while (!device->canReadLine())
        QVERIFY(device->waitForReadyRead(5000));

    char buf2[1024];
    memset(buf2, 0, sizeof(buf2));
    QCOMPARE(socket.readLine(buf2, sizeof(buf2)), lineLength);

    char *c1 = buf;
    char *c2 = buf2;
    while (*c1 && *c2) {
        QCOMPARE(*c1, *c2);
        ++c1;
        ++c2;
    }
    QCOMPARE(*c1, *c2);
}
コード例 #9
0
ファイル: rkcommand.cpp プロジェクト: atikbif/relkonIDE
bool RkCommand::waitAnAnswer(Request &req, QIODevice &io)
{
    static const int maxCnt = 500; // ограничение ожидания ответа при длительном входящем потоке данных
    if(io.isOpen()) {
        QByteArray answer;
        if(io.waitForReadyRead(100)) {
            int cnt=0;
            answer+=io.readAll();
            while(io.waitForReadyRead(10)) {
                answer+=io.readAll();
                cnt++;
                if(cnt>=maxCnt) break;
            }
        }
        req.updateRdData(answer);
        if(answer.count()) return true;
    }
    return false;
}
コード例 #10
0
bool LimitedSocket::readCycle()
{
	QByteArray buffer;
	bool bProblem = false;
	
	QIODevice* pRemote = getRemote();

	if(m_timer.isNull())
	{
		m_prevBytes = 0;
		m_timer.start();
	}
	
	int limit = m_nSpeedLimit;

	do
	{
		QByteArray buf;
		qint64 available;
		
		available = pRemote->bytesAvailable();
		if(!available && !pRemote->waitForReadyRead(10000))
		{
			bProblem = true;
			break;
		}
		
		qint64 toread = (limit) ? limit/2 : available;
		
		if(m_nToTransfer && m_nToTransfer-m_nTransfered < toread)
			toread = m_nToTransfer-m_nTransfered;
		
		buf = pRemote->read(toread);
		buffer += buf;
		m_nTransfered += buf.size();
		
		if(m_nTransfered >= m_nToTransfer && m_nToTransfer)
			break;
	}
	while(buffer.size() < 1024);

	m_file.write(buffer);

	if(bProblem)
	{
		/*if(m_pSocket->state() == QAbstractSocket::ConnectedState) // timeout
			m_strError = tr ( "Timeout" );
		else if(m_pSocket->error() == QAbstractSocket::RemoteHostClosedError)
		{
			if(m_nToTransfer > m_nTransfered && m_nToTransfer)
			{
				qDebug() << "Remote host closed the connection";
				m_strError = tr ( "Connection lost" );
			}
		}
		else
		{
			m_strError = m_pSocket->errorString();
			if ( m_strError.isEmpty() )
			{
				qDebug() << "Connection lost!";
				m_strError = tr ( "Connection lost" );
			}
		}*/
	}
	else if(!m_bAbort)
	{
//		QTime now = QTime::currentTime();
		qulonglong bnow = m_nTransfered;

		int msecs;
		qulonglong bytes = bnow - m_prevBytes;

		if((msecs = m_timer.elapsed()) > 1000)
		{
			m_statsLock.lockForWrite();
			m_stats << QPair<int,qulonglong> ( m_timer.restart(), bytes );
			if(m_stats.size() > SPEED_SAMPLES)
				m_stats.removeFirst();
			m_statsLock.unlock();

			m_prevBytes = bnow;
		}

		if(limit > 0 && bytes)
		{
			int sleeptime = bytes/ ( limit/1000 ) - msecs;
			if(sleeptime > 0)
				msleep(sleeptime*2);
		}
	}

	return !bProblem;
}