void VirtualSerialDevice::flush() { while (waitForBytesWritten(-1)) { /* loop */ } tcflush(d->portHandle, TCIOFLUSH); }
qint64 THttpSocket::writeRawData(const char *data, qint64 size) { qint64 total = 0; if (Q_UNLIKELY(!data || size == 0)) { return total; } for (;;) { if (QTcpSocket::bytesToWrite() > SEND_BUF_SIZE * 3 / 4) { if (Q_UNLIKELY(!waitForBytesWritten())) { tWarn("socket error: waitForBytesWritten function [%s]", qPrintable(errorString())); break; } } qint64 written = QTcpSocket::write(data + total, qMin(size - total, WRITE_LENGTH)); if (Q_UNLIKELY(written <= 0)) { tWarn("socket write error: total:%d (%d)", (int)total, (int)written); return -1; } total += written; if (total >= size) { break; } } idleElapsed = std::time(nullptr); return total; }
void BoxitSocket::sendData(quint16 msgID, QByteArray data) { // Send data in multiple data packages, if data is too big... while (true) { QByteArray subData = data.mid(0, BOXIT_SOCKET_MAX_SIZE); data.remove(0, BOXIT_SOCKET_MAX_SIZE); quint16 subMsgID = msgID; if (!data.isEmpty()) subMsgID = MSG_DATA_PACKAGE_MULTIPLE; // Send data QByteArray block; QDataStream out(&block, QIODevice::WriteOnly); out.setVersion(QDataStream::Qt_4_6); out << (quint16)0; out << (quint16)subMsgID; out << subData; out.device()->seek(0); out << (quint16)(block.size() - 2*sizeof(quint16)); write(block); flush(); waitForBytesWritten(2000); if (data.isEmpty()) break; } }
//Pour envoyer un message complet bool Socket::sendMessage(QByteArray *message) { if(message==NULL) return false; qDebug("Envoi="); qDebug(*message); //On construit le message à envoyer (avec les entetes) QByteArray block; QDataStream out(&block, QIODevice::WriteOnly); //Tous les messages envoyés ont la version Qt 4.0 (pour assurer les compatibilités) out.setVersion(QDataStream::Qt_4_0); //On laisse de la place au début pour écrire la taille du message out << (qint64)0; //On écrit le message out << (*message); //On se replace au début et on écrit la taille du message out.device()->seek(0); out << (qint64)(block.size() - sizeof(qint64)); //On envoi le message final et vérifie que l'envoi a bien commencé if(write(block)==-1) return false; //On attends pour l'envoi waitForBytesWritten(); //On supprime le message et on retourne le résultat de l'envoi delete message; return true; }
bool Connection::onRequestConnect() { QDataStream stream(this); QString name; stream >> name; setPeer(name); qDebug() << "user" << name << "try to connect"; RsaKey key; stream >> key; setFriendRsaKey(key); QString key_str; stream >> key_str; twofish_key.set_str(key_str.toStdString().c_str(), 16); twofish_key = Rsa::crypt(twofish_key, ownPrivateKey); twofish = new Twofish(twofish_key, 128); QString answer = "REQUEST_CONNECT_OK"; stream << answer; waitForBytesWritten(); qDebug() << "connected"; return true; }
bool CTcpClient::sqlBindValue(const QString &placeholder, const QVariant &val){ sendMessage("<"+TCP_SQL_BIND+">"+placeholder+"</"+TCP_SQL_BIND+"><"+TCP_SQL_BINDVALUE+">"+val.toString()+"</"+TCP_SQL_BINDVALUE+">"); waitForBytesWritten(); waitForReadyRead(); return m_retourSql; }
QStringList CTcpClient::connectedPostes() { sendMessage("", TCP_GET_POSTES_CO); waitForBytesWritten(); waitForReadyRead(); return m_lstPostesCo; }
void Connector::callForWait() { qDebug("call For Wait"); QByteArray data(waitOp, 2); write(data); waitForBytesWritten(200); }
quint64 CTcpClient::SendData( const QByteArray & byteArray ) { HandleDisconnect( ); quint64 nRet = 0; int nPackageSize = 10 * 1024 * 1024; int nTotalSize = byteArray.count( ); int nMode = nTotalSize / nPackageSize; int nSurplus = nTotalSize % nPackageSize; const char* pData = byteArray.data( ); const char* pPkgData = NULL; if ( 0 == nMode ) { // < 10M nRet += write( byteArray ); } else { // >= 10M int nIndex = 0; for ( nIndex = 0; nIndex < nMode; nIndex++ ) { pPkgData = ( pData + nIndex * nPackageSize ); nRet += write( pPkgData, nPackageSize ); } if ( 0 != nSurplus ) { pPkgData = ( pData + nIndex * nPackageSize ); nRet += write( pPkgData, nSurplus ); } } if ( !flush( ) ) { waitForBytesWritten( ); } return nRet; }
bool QLocalSocket_QtDShell::__override_waitForBytesWritten(int msecs0, bool static_call) { if (static_call) { return QLocalSocket::waitForBytesWritten((int )msecs0); } else { return waitForBytesWritten((int )msecs0); } }
bool QTemporaryFile_QtDShell::__override_waitForBytesWritten(int msecs0, bool static_call) { if (static_call) { return QIODevice::waitForBytesWritten((int )msecs0); } else { return waitForBytesWritten((int )msecs0); } }
void DkConnection::sendNewGoodbyeMessage() { //qDebug() << "sending good bye to " << peerName() << ":" << this->peerPort(); QByteArray ba = "GoodBye"; // scherz? QByteArray data = "GOODBYE"; data.append(SeparatorToken).append(QByteArray::number(ba.size())).append(SeparatorToken).append(ba); write(data); waitForBytesWritten(); }
/*! Closes all communication with the process. After calling this function, QProcess will no longer emit readyRead(), and data can no longer be read or written. */ void QProcess::close() { emit aboutToClose(); while (waitForBytesWritten(-1)) ; kill(); waitForFinished(-1); setOpenMode(QIODevice::NotOpen); }
void Connector::callForData(qint8 start, qint8 num) { qDebug("call For Data"); QByteArray data(readOp, 10); data[8] = start; data[9] = num; write(data); waitForBytesWritten(200); }
void Connector::startWrite(qint8 start, qint8 num, QByteArray data) { qDebug()<<"Connector::startWrite"; QByteArray toWrite(writeOp, 10); toWrite[0] = toWrite[0] + data.size(); toWrite[8] = start; toWrite[9] = num; toWrite.append(data); write(toWrite); waitForBytesWritten(500); emit writeOK(); }
void Connection::onMessageRecivied() { QDataStream stream(this); ByteArray encrypted; ByteArray::read(stream, encrypted); qDebug() << "recieved: " << encrypted << "msg_length " << encrypted.msg_length; QString decrypted = twofish->decrypt_qstr(encrypted); QString request = "MESSAGE_DELIVERED"; stream << request; waitForBytesWritten(); emit messageRecivied(decrypted); qDebug() << "new message from:" << peer; qDebug() << decrypted; }
qint64 THttpSocket::writeRawData(const char *data, qint64 size) { qint64 total = 0; for (;;) { qint64 written = QTcpSocket::write(data + total, qMin(size - total, WRITE_LENGTH)); if (written <= 0) { tWarn("socket write error: total:%d (%d)", (int)total, (int)written); return -1; } total += written; if (total >= size) break; if (!waitForBytesWritten()) { tWarn("socket error: waitForBytesWritten function [%s]", qPrintable(errorString())); break; } } return total; }
bool DhQIODevice::DvhwaitForBytesWritten(int x1) { return waitForBytesWritten(x1); }
void CTcpClient::sqlRequete(QString requete) { sendMessage(requete, TCP_REQUETE); waitForBytesWritten(); // waitForReadyRead(); }
bool DhQAbstractSocket::DvhwaitForBytesWritten(int x1) { return waitForBytesWritten(x1); }
void VirtualSerialDevice::flush() { while (waitForBytesWritten(-1)) { /* loop */ } }