Example #1
0
void BConsole::sn_write()
{
	d->w->deleteLater();
	d->w = 0;

	if(bytesToWrite() > 0)
		tryWrite();
	if(bytesToWrite() == 0 && d->closing) {
		d->closing = false;
		d->closed = true;
		delayedCloseFinished();
	}
}
Example #2
0
void CG2Node::FlushSendQueue(bool bFullFlush)
{
    QByteArray* pOutput = GetOutputBuffer();

	while( bytesToWrite() == 0 && m_lSendQueue.size() )
	{
		while( pOutput->size() < 4096 && m_lSendQueue.size() )
		{
			G2Packet* pPacket = m_lSendQueue.dequeue();
			pPacket->ToBuffer(pOutput);
			pPacket->Release();
		}
		emit readyToTransfer();
	}


    if( bFullFlush )
    {
        if( m_bCompressedOutput && pOutput->size() )
            m_bOutputPending = true;
    }

    if( pOutput->size() )
        emit readyToTransfer();
}
Example #3
0
bool InBandStream::sendNextPaket(bool AFlush)
{
	bool sent = false;
	if (isOpen() && FDataIqRequestId.isEmpty() && (bytesToWrite()>=FBlockSize || AFlush))
	{
		FThreadLock.lockForWrite();
		QByteArray data = FWriteBuffer.read(FBlockSize);
		FThreadLock.unlock();

		if (!data.isEmpty())
		{
			if (FStanzaProcessor)
			{
				Stanza paket(FStanzaType==StanzaMessage ? STANZA_KIND_MESSAGE : STANZA_KIND_IQ);
				paket.setTo(FContactJid.full()).setUniqueId();

				QDomElement dataElem = paket.addElement("data",NS_INBAND_BYTESTREAMS);
				dataElem.setAttribute("sid",FStreamId);
				dataElem.setAttribute("seq",FSeqOut);
				dataElem.appendChild(paket.createTextNode(QString::fromUtf8(data.toBase64())));

				if (FStanzaType == StanzaMessage)
				{
					QDomElement ampElem = paket.addElement("amp","http://jabber.org/protocol/amp");
					QDomElement ruleElem = ampElem.appendChild(paket.createElement("rule")).toElement();
					ruleElem.setAttribute("condition","deliver");
					ruleElem.setAttribute("value","stored");
					ruleElem.setAttribute("action","error");
					ruleElem = ampElem.appendChild(paket.createElement("rule")).toElement();
					ruleElem.setAttribute("condition","match-resource");
					ruleElem.setAttribute("value","exact");
					ruleElem.setAttribute("action","error");

					DataEvent *dataEvent = new DataEvent(AFlush);
					QCoreApplication::postEvent(this, dataEvent);

					sent = FStanzaProcessor->sendStanzaOut(FStreamJid,paket);
				}
				else
				{
					paket.setType(STANZA_TYPE_SET);
					FDataIqRequestId = paket.id();
					sent = FStanzaProcessor->sendStanzaRequest(this,FStreamJid,paket,DATA_TIMEOUT);
				}
			}

			if (sent)
			{
				FSeqOut = FSeqOut<USHRT_MAX ? FSeqOut+1 : 0;
				emit bytesWritten(data.size());
				FBytesWrittenCondition.wakeAll();
			}
			else
			{
				abort(XmppError(IERR_INBAND_STREAM_DATA_NOT_SENT));
			}
		}
	}
	return sent;
}
void QLocalSocket::close()
{
    Q_D(QLocalSocket);
    if (state() == UnconnectedState)
        return;

    QIODevice::close();
    d->state = ClosingState;
    emit stateChanged(d->state);
    if (!d->pipeClosed)
        emit readChannelFinished();
    d->serverName = QString();
    d->fullServerName = QString();

    if (state() != UnconnectedState && bytesToWrite() > 0) {
        disconnectFromServer();
        return;
    }
    d->readSequenceStarted = false;
    d->pendingReadyRead = false;
    d->pipeClosed = false;
    DisconnectNamedPipe(d->handle);
    CloseHandle(d->handle);
    d->handle = INVALID_HANDLE_VALUE;
    ResetEvent(d->overlapped.hEvent);
    d->state = UnconnectedState;
    emit stateChanged(d->state);
    emit disconnected();
    if (d->pipeWriter) {
        delete d->pipeWriter;
        d->pipeWriter = 0;
    }
}
Example #5
0
qint64  QLocalSocket_QtDShell::__override_bytesToWrite(bool static_call) const
{
    if (static_call) {
        return QLocalSocket::bytesToWrite();
    } else {
        return bytesToWrite();
    }
}
Example #6
0
qint64  QTemporaryFile_QtDShell::__override_bytesToWrite(bool static_call) const
{
    if (static_call) {
        return QIODevice::bytesToWrite();
    } else {
        return bytesToWrite();
    }
}
Example #7
0
//!
//! Writes array \a a to the stream.
void ByteStream::write(const QByteArray &a)
{
	if(!isOpen())
		return;

	bool doWrite = bytesToWrite() == 0 ? true: false;
	appendWrite(a);
	if(doWrite)
		tryWrite();
}
Example #8
0
void HttpPoll::close()
{
	if(d->state == 0 || d->closing)
		return;

	if(bytesToWrite() == 0)
		reset();
	else
		d->closing = true;
}
Example #9
0
bool InBandStream::flush()
{
	if (isOpen() && bytesToWrite()>0)
	{
		DataEvent *dataEvent = new DataEvent(true);
		QCoreApplication::postEvent(this,dataEvent);
		return true;
	}
	return false;
}
Example #10
0
void Win_QextSerialPort::monitorCommEvent()
{
    DWORD eventMask = 0;

    ResetEvent(m_Overlap.hEvent);
    if (!WaitCommEvent(m_WinHandle, & eventMask, & m_Overlap))
    {
        if (GetLastError() != ERROR_IO_PENDING)
        {
            qCritical("WaitCommEvent error %ld\n", GetLastError());
        }
    }

    if (WaitForSingleObject(m_Overlap.hEvent, INFINITE) == WAIT_OBJECT_0) 
    {
        //overlap event occured
        DWORD undefined;
        if (!GetOverlappedResult(m_WinHandle, & m_Overlap, & undefined, false)) 
        {
            qWarning("Comm event overlapped error %ld", GetLastError());
            return;
        }
        if (eventMask & EV_RXCHAR) 
        {
            if (sender() != this)
                emit readyRead();
        }
        if (eventMask & EV_TXEMPTY) 
        {
            DWORD numBytes;
            GetOverlappedResult(m_WinHandle, & m_OverlapWrite, & numBytes, true);
            m_pBytesToWriteLock->lockForWrite();

            if (sender() != this)
            {
                emit bytesWritten(bytesToWrite());
            }

            m_BytesToWrite = 0;
            m_pBytesToWriteLock->WriteUnlock();
        }
        if (eventMask & EV_DSR)
        {
            if (lineStatus() & LS_DSR)
            {
                emit dsrChanged(true);
            }
            else
            {
                emit dsrChanged(false);
            }
        }
    }
}
Example #11
0
void BConsole::close()
{
	if(d->closing || d->closed)
		return;

	if(bytesToWrite() > 0)
		d->closing = true;
	else {
		::fclose(stdout);
		d->closed = true;
	}
}
void FTPActiveTextDataOut::connectionClosedSlot(){
    //qDebug()<<"FTPActiveTextDataOut::connectionClosedSlot()";
    if(bytesToWrite()!=0){
        // идёт запись а соединение закрыто
        emit connectionCloseByClientSignal();
    }
    else{
        // записи нет и соединение закрывается
        //qDebug()<<"FTPActiveTextDataOut emit sendTextDataSuccessfulSignal()";
        emit sendTextDataSuccessfulSignal();
    }
}
Example #13
0
void QLocalSocket::close()
{
    Q_D(QLocalSocket);
    if (openMode() == NotOpen)
        return;

    QIODevice::close();
    d->serverName = QString();
    d->fullServerName = QString();

    if (state() != UnconnectedState) {
        if (bytesToWrite() > 0) {
            disconnectFromServer();
            return;
        }

        d->_q_pipeClosed();
    }
}
Example #14
0
qint64 OutputDirectSound::writeAudio(unsigned char *data, qint64 len)
{
    unsigned char *ptr = 0, *ptr2 = 0;
    DWORD size = 0, size2 = 0;

    DWORD available = bytesToWrite(); //available bytes
    if(available < 128)
    {
        usleep(5000);
        return 0;
    }
    DWORD lockSize = qMin((DWORD)len, available); //required size

    HRESULT result = m_dsBuffer->Lock(m_dsBufferAt, lockSize,
                                      (void**)&ptr, (DWORD*)&size,
                                      (void**)&ptr2, (DWORD*)&size2, 0);
    if(result == DSERR_BUFFERLOST)
    {
        m_dsBuffer->Restore();
        result = m_dsBuffer->Lock(m_dsBufferAt, lockSize,
                                  (void**)&ptr, (DWORD*)&size,
                                  (void**)&ptr2, (DWORD*)&size2, 0);
    }
    if(result != DS_OK)
    {
        qWarning("OutputDirectSound: unable to lock buffer, error = 0x%lx", result);
        return -1;
    }

    DWORD totalSize = size + size2; //total locked size
    memmove(ptr, data, size);
    if(size2 > 0)
        memmove(ptr2, data + size, size2);

    m_dsBuffer->Unlock((void*)ptr, size, (void*)ptr2, size2);

    m_dsBufferAt += totalSize;
    m_dsBufferAt %= DS_BUFSIZE;
    return totalSize;
}
Example #15
0
void SerialDev::start () {
    QByteArray buffer;
    if ((bytesToWrite() == 0) && Bufferize::instance()->getBuffer(buffer)) {
        sendMsg (buffer);
    }
}
Example #16
0
qint64 DhQAbstractSocket::DvhbytesToWrite() const {
  return bytesToWrite();
}
Example #17
0
void HttpPoll::http_result()
{
	// check for death :)
	QPointer<QObject> self = this;
	syncFinished();
	if(!self)
		return;

	// get id and packet
	QString id;
	QString cookie = d->http.getHeader("Set-Cookie");
	int n = cookie.indexOf("ID=");
	if(n == -1) {
		reset();
		error(ErrRead);
		return;
	}
	n += 3;
	int n2 = cookie.indexOf(';', n);
	if(n2 != -1)
		id = cookie.mid(n, n2-n);
	else
		id = cookie.mid(n);
	QByteArray block = d->http.body();

	// session error?
	if(id.right(2) == ":0") {
		if(id == "0:0" && d->state == 2) {
			reset();
			connectionClosed();
			return;
		}
		else {
			reset();
			error(ErrRead);
			return;
		}
	}

	d->ident = id;
	bool justNowConnected = false;
	if(d->state == 1) {
		d->state = 2;
		justNowConnected = true;
	}

	// sync up again soon
	if(bytesToWrite() > 0 || !d->closing) {
		d->t->start(d->polltime * 1000);
  }

	// connecting
	if(justNowConnected) {
		connected();
	}
	else {
		if(!d->out.isEmpty()) {
			int x = d->out.size();
			d->out.resize(0);
			takeWrite(x);
			bytesWritten(x);
		}
	}

	if(!self)
		return;

	if(!block.isEmpty()) {
		appendRead(block);
		readyRead();
	}

	if(!self)
		return;

	if(bytesToWrite() > 0) {
		do_sync();
	}
	else {
		if(d->closing) {
			reset();
			delayedCloseFinished();
			return;
		}
	}
}
Example #18
0
qint64 DhQIODevice::DvhbytesToWrite() const {
  return bytesToWrite();
}