From c334ddf014c2932fbe7f7d2d83b5d3b6c02269ad Mon Sep 17 00:00:00 2001 From: Jorge Cuadrado Date: Fri, 9 Nov 2007 22:31:44 -0500 Subject: [PATCH] Improved network support --- src/dash/network/socket.cpp | 53 +++++++++++++++++++++++-------- src/dashserver/project/projectmanager.cpp | 1 + src/shell/networkhandler.cpp | 2 +- 3 files changed, 42 insertions(+), 14 deletions(-) diff --git a/src/dash/network/socket.cpp b/src/dash/network/socket.cpp index 6ce1071..7e6ce57 100644 --- a/src/dash/network/socket.cpp +++ b/src/dash/network/socket.cpp @@ -101,8 +101,29 @@ void Socket::send(const QByteArray &data) { case Text: { - QTextStream stream(this); - stream << data.toBase64() << "%%" << endl; +// QTextStream stream(this); +// stream << data.toBase64() << "%%" << endl; + + + QByteArray toSend = data.toBase64()+"%%\n"; + QByteArray block; + + dfDebug << "ENVIANDO " << toSend.size() << " bytes"; + + for(int i = 0; i < toSend.size(); i++) + { + block += toSend[i]; + if( i % 1024 == 0 ) + { + write(block); + block = QByteArray(); + } + } + + if( !block.isEmpty() ) + { + write(block); + } } break; case Binary: @@ -130,24 +151,30 @@ void Socket::readFromServer() case Text: { QString readed; - while(this->canReadLine()) +// while(this->canReadLine()) + + while(bytesAvailable() > 0 ) { - readed += this->readLine(); + bool process = false; + readed += this->readLine(); //this->read(1024); if ( readed.endsWith("%%\n") ) { readed.remove(readed.lastIndexOf("%%"), 2); - break; + process = true; } - } - if ( !readed.isEmpty() ) - { - readed = QByteArray::fromBase64(readed.toLocal8Bit()); - - foreach(SocketObserver *o, d->observers) + if( process && !readed.isEmpty() ) { - o->readed(readed); + readed = QByteArray::fromBase64(readed.toLocal8Bit()); + + foreach(SocketObserver *o, d->observers) + { + o->readed(readed); + } + readed = QString(); + + if( d->format != Text ) break; } } } @@ -166,7 +193,7 @@ void Socket::readFromServer() break; } - if (this->bytesAvailable() > 0) readFromServer(); + if (this->bytesAvailable() > 0) emit readyRead(); } } diff --git a/src/dashserver/project/projectmanager.cpp b/src/dashserver/project/projectmanager.cpp index b92baf3..f754949 100644 --- a/src/dashserver/project/projectmanager.cpp +++ b/src/dashserver/project/projectmanager.cpp @@ -301,6 +301,7 @@ void Manager::handlePackage(DashServer::Package* const pkg) DashServer::Connection *cnn = pkg->source(); cnn->sendToClient(xml, true); + delete project; } } } diff --git a/src/shell/networkhandler.cpp b/src/shell/networkhandler.cpp index ebc5252..d13a8f1 100644 --- a/src/shell/networkhandler.cpp +++ b/src/shell/networkhandler.cpp @@ -136,7 +136,7 @@ void NetworkHandler::execute(YAMF::Command::Base *cmd) dfDebug << "ENCOLANDO: " << cmd->toXml(); m_commands.enqueue(cmd); - if( !m_sign.isEmpty() && isEmpty && !m_waitingResponse ) + if( isEmpty && !m_waitingResponse && !m_sign.isEmpty() ) { m_waitingResponse = true; send(cmd->toXml()); -- 2.11.4.GIT