bool QIODeviceProto::waitForBytesWritten(int msecs)
{
  QIODevice *item = qscriptvalue_cast<QIODevice*>(thisObject());
  if (item)
    return item->waitForBytesWritten(msecs);
  return false;
}
Ejemplo n.º 2
0
	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;
	}
Ejemplo n.º 3
0
bool LimitedSocket::writeCycle()
{
	int toRead;
	QByteArray buffer;
	QIODevice* pRemote = getRemote();
	
	if(m_timer.isNull())
	{
		m_prevBytes = 0;
		m_timer.start();
	}
	
	toRead = qMin<qint64>(1024*16, m_nToTransfer-m_nTransfered);
	buffer = m_file.read(toRead);
	
	if(buffer.size() < toRead)
	{
		m_strError = tr("Error reading file");
		return false;
	}
	
	pRemote->write(buffer);
	if(!pRemote->waitForBytesWritten(10000))
		return false;
	
	m_nTransfered += toRead;
	
    //QTime now = QTime::currentTime();
	int msecs;
	qint64 bytes = m_nTransfered - 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 = m_nTransfered;
	}
	
	if(m_nSpeedLimit > 0 && bytes)
	{
		int sleeptime = bytes/(m_nSpeedLimit/1000) - msecs;
		if(sleeptime > 0)
			msleep(sleeptime*2);
	}
	
    return true;
}