コード例 #1
0
void RequestManager::dataFinishedBuffering()
{
    // get a pointer to the calling socket
    QTcpSocket * socket = qobject_cast<QTcpSocket*>(sender());
    // get the buffered message associated
    QByteArray current_buffered(mRequestBuffer[socket]);
    // get the end of the message
    current_buffered.append(socket->readAll());

    // remove the socket and disconnect its from the RequestManager slots
    mRequestBuffer.remove(socket);
    disconnect(socket, SIGNAL(readyRead()),this,SLOT(dataReadyForBuffering()));
    disconnect(socket, SIGNAL(readChannelFinished()),this,SLOT(dataFinishedBuffering()));
    qDebug() << "Finishing Message" << current_buffered;
    if(current_buffered.size() > 4)
        // Process the buffered message
        processMessage(current_buffered);
}
コード例 #2
0
bool QNmeaPositionInfoSourcePrivate::openSourceDevice()
{
    if (!m_device) {
        qWarning("QNmeaPositionInfoSource: no QIODevice data source, call setDevice() first");
        return false;
    }

    if (!m_device->isOpen() && !m_device->open(QIODevice::ReadOnly)) {
        qWarning("QNmeaPositionInfoSource: cannot open QIODevice data source");
        return false;
    }

    connect(m_device, SIGNAL(aboutToClose()), SLOT(sourceDataClosed()));
    connect(m_device, SIGNAL(readChannelFinished()), SLOT(sourceDataClosed()));
    connect(m_device, SIGNAL(destroyed()), SLOT(sourceDataClosed()));

    return true;
}
コード例 #3
0
void QNetworkReplyImplPrivate::_q_bufferOutgoingData()
{
    Q_Q(QNetworkReplyImpl);

    if (!outgoingDataBuffer) {
        // first call, create our buffer
        outgoingDataBuffer = new QRingBuffer();

        QObject::connect(outgoingData, SIGNAL(readyRead()), q, SLOT(_q_bufferOutgoingData()));
        QObject::connect(outgoingData, SIGNAL(readChannelFinished()), q, SLOT(_q_bufferOutgoingDataFinished()));
    }

    qint64 bytesBuffered = 0;
    qint64 bytesToBuffer = 0;

    // read data into our buffer
    forever {
        bytesToBuffer = outgoingData->bytesAvailable();
        // unknown? just try 2 kB, this also ensures we always try to read the EOF
        if (bytesToBuffer <= 0)
            bytesToBuffer = 2*1024;

        char *dst = outgoingDataBuffer->reserve(bytesToBuffer);
        bytesBuffered = outgoingData->read(dst, bytesToBuffer);

        if (bytesBuffered == -1) {
            // EOF has been reached.
            outgoingDataBuffer->chop(bytesToBuffer);

            _q_bufferOutgoingDataFinished();
            break;
        } else if (bytesBuffered == 0) {
            // nothing read right now, just wait until we get called again
            outgoingDataBuffer->chop(bytesToBuffer);

            break;
        } else {
            // don't break, try to read() again
            outgoingDataBuffer->chop(bytesToBuffer - bytesBuffered);
        }
    }
}
コード例 #4
0
ファイル: inbandstream.cpp プロジェクト: ChALkeR/vacuum-im
void InBandStream::setStreamState(int AState)
{
	if (streamState() != AState)
	{
		if (AState == IDataStreamSocket::Opened)
		{
			FSeqIn = 0;
			FSeqOut = 0;
			FDataIqRequestId.clear();
			FThreadLock.lockForWrite();
			QIODevice::open(openMode());
			FThreadLock.unlock();
			LOG_STRM_INFO(FStreamJid,QString("In-band stream opened, sid=%1, stanzaType=%2").arg(FStreamId).arg(FStanzaType));
		}
		else if (AState == IDataStreamSocket::Closed)
		{
			removeStanzaHandle(FSHIOpen);
			removeStanzaHandle(FSHIClose);
			removeStanzaHandle(FSHIData);
			emit readChannelFinished();

			FThreadLock.lockForWrite();
			FStreamState = AState;
			QString saveError = QIODevice::errorString();
			QIODevice::close();
			QIODevice::setErrorString(saveError);
			FReadBuffer.clear();
			FWriteBuffer.clear();
			FThreadLock.unlock();

			FReadyReadCondition.wakeAll();
			FBytesWrittenCondition.wakeAll();
			LOG_STRM_INFO(FStreamJid,QString("In-band stream closed, sid=%1").arg(FStreamId));
		}

		FThreadLock.lockForWrite();
		FStreamState = AState;
		FThreadLock.unlock();

		emit stateChanged(AState);
	}
}
コード例 #5
0
// this is used when it was fetched from the cache, right?
void QNetworkReplyImplPrivate::appendDownstreamData(QIODevice *data)
{
    Q_Q(QNetworkReplyImpl);
    if (!q->isOpen())
        return;

    // read until EOF from data
    if (copyDevice) {
        qCritical("QNetworkReplyImpl: copy from QIODevice already in progress -- "
                  "backend probly needs to be fixed");
        return;
    }

    copyDevice = data;
    q->connect(copyDevice, SIGNAL(readyRead()), SLOT(_q_copyReadyRead()));
    q->connect(copyDevice, SIGNAL(readChannelFinished()), SLOT(_q_copyReadChannelFinished()));

    // start the copy:
    _q_copyReadyRead();
}
コード例 #6
0
ファイル: qxtstdio.cpp プロジェクト: develnk/qxtweb-qt5
/*!
    \reimp
 */
bool QxtStdio::waitForReadyRead(int)
{
    if (qxt_d().hadeof)
        return false;


    char c = getchar();
    if (c == EOF)
    {
#if QT_VERSION >= 0x040400
        emit readChannelFinished();
#endif
        qxt_d().hadeof = true;
        return false;
    }
    QByteArray b(1, c);
    enqueData(b);
    sendData(b);
    return true;
}
コード例 #7
0
void QObjectHandler::process(QHttpSocket *socket, const QString &path)
{
    // Only POST requests are accepted - reject any other methods but ensure
    // that the Allow header is set in order to comply with RFC 2616
    if(socket->method() != "POST") {
        socket->setHeader("Allow", "POST");
        socket->writeError(QHttpSocket::MethodNotAllowed);
        return;
    }

    // Determine the index of the slot with the specified name - note that we
    // don't need to worry about retrieving the index for deleteLater() since
    // we specify the "QVariantMap" parameter type, which no parent slots use
    int index = metaObject()->indexOfSlot(QString("%1(QVariantMap)").arg(path).toUtf8().data());

    // If the index is invalid, the "resource" was not found
    if(index == -1) {
        socket->writeError(QHttpSocket::NotFound);
        return;
    }

    // Ensure that the return type of the slot is QVariantMap
    QMetaMethod method = metaObject()->method(index);
    if(method.returnType() != QMetaType::QVariantMap) {
        socket->writeError(QHttpSocket::InternalServerError);
        return;
    }

    // Check to see if the socket has finished receiving all of the data yet
    // or not - if so, jump to invokeSlot(), otherwise wait for the
    // readChannelFinished() signal
    if(socket->bytesAvailable() >= socket->contentLength()) {
        d->invokeSlot(socket, index);
    } else {

        // Add the socket and index to the map so that the latter can be
        // retrieved when the readChannelFinished() signal is emitted
        d->map.insert(socket, index);
        connect(socket, SIGNAL(readChannelFinished()), d, SLOT(onReadChannelFinished()));
    }
}
コード例 #8
0
ファイル: qxtstdio.cpp プロジェクト: develnk/qxtweb-qt5
/*!Blocks until EOF is received.*/
void QxtStdio::waitForEOF()
{
    if (qxt_d().hadeof)
        return;

    forever
    {
        char c = getchar();
        if (c == EOF)
        {
#if QT_VERSION >= 0x040400
            emit readChannelFinished();
#endif
            qxt_d().hadeof = true;
            return;
        }
        QByteArray b(1, c);
        enqueData(b);
        sendData(b);
    }
}
コード例 #9
0
ファイル: caudiooutputtest.cpp プロジェクト: weinkym/src_miao
void CAudioOutputTest::start(const QString &filePath, const QAudioDeviceInfo &audioDeviceInfo)
{
    stop();

    if(m_PCMIODevice)
    {
        m_PCMIODevice->deleteLater();
        m_PCMIODevice = NULL;
    }
    m_PCMIODevice = new CPCMIODevice(filePath,this);
    connect(m_PCMIODevice,SIGNAL(readChannelFinished()),this,SLOT(onStateChanged()));

    QAudioFormat format;
    format.setSampleRate(44100);
    format.setChannelCount(2);
    format.setSampleSize(16);
    format.setCodec("audio/pcm");
    format.setByteOrder(QAudioFormat::LittleEndian);
    format.setSampleType(QAudioFormat::SignedInt);

    QAudioDeviceInfo info(audioDeviceInfo);
    if (!info.isFormatSupported(format)) {
//        qWarning() << "Default format not supported - trying to use nearest";
        format = info.nearestFormat(format);
    }

    if(m_audioOutput)
    {
        delete m_audioOutput;
        m_audioOutput = 0;
    }
    m_audioOutput = new QAudioOutput(audioDeviceInfo, format, this);
    connect(m_audioOutput,SIGNAL(stateChanged(QAudio::State)),this,SLOT(onStateChanged()));

    if(m_PCMIODevice)
    {
        m_PCMIODevice->start();
    }
    m_audioOutput->start(m_PCMIODevice);
}
コード例 #10
0
void NewstuffModel::retrieveData()
{
    if ( d->m_currentReply && d->m_currentReply->isReadable() ) {
        // check if we are redirected
        const QVariant redirectionAttribute = d->m_currentReply->attribute( QNetworkRequest::RedirectionTargetAttribute );
        if ( !redirectionAttribute.isNull() ) {
            d->m_currentReply = d->m_networkAccessManager.get( QNetworkRequest( redirectionAttribute.toUrl() ) );
            QObject::connect( d->m_currentReply, SIGNAL(readyRead()), this, SLOT(retrieveData()) );
            QObject::connect( d->m_currentReply, SIGNAL(readChannelFinished()), this, SLOT(retrieveData()) );
            QObject::connect( d->m_currentReply, SIGNAL(downloadProgress(qint64,qint64)),
                              this, SLOT(updateProgress(qint64,qint64)) );
        } else {
            d->m_currentFile->write( d->m_currentReply->readAll() );
            if ( d->m_currentReply->isFinished() ) {
                d->m_currentReply->deleteLater();
                d->m_currentReply = nullptr;
                d->m_currentFile->flush();
                d->installMap();
            }
        }
    }
}
コード例 #11
0
void KVNetworkReply::handleResponse() {
	if(d->finished) return;

	setError(d->copied->error(), d->copied->errorString());

	copyAttribute(QNetworkRequest::HttpStatusCodeAttribute);
	copyAttribute(QNetworkRequest::HttpReasonPhraseAttribute);
	copyAttribute(QNetworkRequest::RedirectionTargetAttribute);
	copyAttribute(QNetworkRequest::ConnectionEncryptedAttribute);
	copyAttribute(QNetworkRequest::SourceIsFromCacheAttribute);
	copyAttribute(QNetworkRequest::HttpPipeliningWasUsedAttribute);

	QList<QNetworkReply::RawHeaderPair> headers = d->copied->rawHeaderPairs();
	for(int i = 0; i < headers.size(); i++)
		setRawHeader(headers[i].first, headers[i].second);

	QByteArray data = d->copied->readAll();
	d->copied->abort();

	//qDebug() << "content:" << data;

	this->postToTool(data);
	this->writeToDisk(data);

	if(d->translate)
		data = KVTranslator::instance().translateJson(data, d->copied->url().path().split("/").last());

	d->content = data;
	d->offset = 0;
	setHeader(QNetworkRequest::ContentLengthHeader, QVariant(d->content.size()));

	open(ReadOnly | Unbuffered);
	//qDebug() << "translated:" << d->content.constData();

	d->finished = true;

	emit finished();
	emit readChannelFinished();
}
コード例 #12
0
void EngineProcess::start(const QString& program,
			  const QStringList& arguments,
			  OpenMode mode)
{
	if (m_started)
		close();

	m_started = false;
	m_finished = false;
	m_exitCode = 0;
	m_exitStatus = NormalExit;
	m_errRead = createFile(m_stdErrFile, m_stdErrFileMode);

	// Temporary handles for the child process' end of the pipes
	HANDLE outWrite;
	HANDLE inRead;

	// Security attributes. Use the same one for both pipes.
	SECURITY_ATTRIBUTES saAttr;
	saAttr.nLength = sizeof(SECURITY_ATTRIBUTES);
	saAttr.bInheritHandle = TRUE;
	saAttr.lpSecurityDescriptor = NULL;

	CreatePipe(&m_outRead, &outWrite, &saAttr, 0);
	CreatePipe(&inRead, &m_inWrite, &saAttr, 0);

	STARTUPINFO startupInfo;
	ZeroMemory(&startupInfo, sizeof(startupInfo));
	startupInfo.cb = sizeof(startupInfo);
	startupInfo.hStdError = m_errRead;
	startupInfo.hStdOutput = outWrite;
	startupInfo.hStdInput = inRead;
	startupInfo.dwFlags |= STARTF_USESTDHANDLES;

	// Call DuplicateHandle with a NULL target to get non-inheritable
	// handles for the parent process' ends of the pipes
	DuplicateHandle(GetCurrentProcess(),
			m_outRead,		// child's stdout read end
			GetCurrentProcess(),
			NULL,			// no target
			0,			// flags
			FALSE,			// not inheritable
			DUPLICATE_SAME_ACCESS);	// same handle access
	DuplicateHandle(GetCurrentProcess(),
			m_inWrite,		// child's stdin write end
			GetCurrentProcess(),
			NULL,			// no target
			0,			// flags
			FALSE,			// not inheritable
			DUPLICATE_SAME_ACCESS);	// same handle access

	BOOL ok = FALSE;
	QString cmd = cmdLine(m_workDir, program, arguments);
	QString wdir = QDir::toNativeSeparators(m_workDir);
	ZeroMemory(&m_processInfo, sizeof(m_processInfo));

#ifdef UNICODE
	ok = CreateProcessW(NULL,
			    (WCHAR*)cmd.utf16(),
			    NULL,	// process attributes
			    NULL,	// thread attributes
			    TRUE,	// inherit handles
			    CREATE_NEW_PROCESS_GROUP | CREATE_NO_WINDOW, // creation flags
			    NULL,	// environment
			    wdir.isEmpty() ? NULL : (WCHAR*)wdir.utf16(),
			    &startupInfo,
			    &m_processInfo);
#else // not UNICODE
	ok = CreateProcessA(NULL,
			    cmd.toLocal8Bit().data(),
			    NULL,	// process attributes
			    NULL,	// thread attributes
			    TRUE,	// inherit handles
			    CREATE_NEW_PROCESS_GROUP | CREATE_NO_WINDOW, // creation flags
			    NULL,	// environment
			    wdir.isEmpty() ? NULL : wdir.toLocal8Bit().data(),
			    &startupInfo,
			    &m_processInfo);
#endif // not UNICODE

	m_started = (bool)ok;
	if (ok)
	{
		// Assign the engine process to the main job to make sure it's
		// terminated when CuteChess terminates.
		AssignProcessToJobObject(mainJob(), m_processInfo.hProcess);

		// Close the child process' ends of the pipes to make sure
		// that ReadFile and WriteFile will return when the child
		// terminates and closes its pipes
		killHandle(&outWrite);
		killHandle(&inRead);
		killHandle(&m_processInfo.hThread);

		// Start reading input from the child
		m_reader = new PipeReader(m_outRead, this);
		connect(m_reader, SIGNAL(finished()), this, SLOT(onFinished()));
		connect(m_reader, SIGNAL(finished()), this, SIGNAL(readChannelFinished()));
		connect(m_reader, SIGNAL(readyRead()), this, SIGNAL(readyRead()));
		m_reader->start();

		// Make QIODevice aware that the device is now open
		QIODevice::open(mode);
	}
	else
		cleanup();
}
コード例 #13
0
SerialDevice::SerialDevice(QObject *parent) : QIODevice(parent)
{
    connect(this, SIGNAL(aboutToClose()), this, SIGNAL(readChannelFinished()));
}