diff --git a/src/network/parallelconnection.cpp b/src/network/parallelconnection.cpp index c9f9b31682..e17603735f 100644 --- a/src/network/parallelconnection.cpp +++ b/src/network/parallelconnection.cpp @@ -86,7 +86,7 @@ namespace openspace { _isConnected(false), _isListening(false) { - + } ParallelConnection::~ParallelConnection(){ @@ -94,6 +94,7 @@ namespace openspace { } void ParallelConnection::clientConnect(){ + //we're already connected, do nothing (dummy check) if(_isConnected.load()){ return; @@ -267,7 +268,7 @@ namespace openspace { default: //unknown message type break; - } + } } void ParallelConnection::decodeInitializationMessage(){ @@ -531,28 +532,47 @@ namespace openspace { std::vector scripts = OsEng.scriptEngine()->cachedScripts(); uint16_t numScrips = scripts.size(); - //write header - buffer.clear(); - writeHeader(buffer, MessageTypes::Initialization); - - //write number of scripts - buffer.insert(buffer.end(), reinterpret_cast(&numScrips), reinterpret_cast(&numScrips) + sizeof(numScrips)); - - uint16_t msglen; + uint16_t scriptlen; + uint32_t totlen = 0; std::vector::const_iterator it; + std::vector scriptMsg; //write all scripts for(it = scripts.cbegin(); it != scripts.cend(); ++it){ //write size of script in chars - msglen = (*it).size(); - buffer.insert(buffer.end(), reinterpret_cast(msglen), reinterpret_cast(msglen) + sizeof(msglen)); - buffer.insert(buffer.end(), (*it).begin(), (*it).end()); + scriptlen = (*it).size(); + scriptMsg.insert(scriptMsg.end(), reinterpret_cast(&scriptlen), reinterpret_cast(&scriptlen) + sizeof(scriptlen)); + + //write actual scripts + scriptMsg.insert(scriptMsg.end(), (*it).begin(), (*it).end()); + + //add script length to total data length + totlen += static_cast(scriptlen) + sizeof(scriptlen); } + //clear buffer + buffer.clear(); + + //write header + writeHeader(buffer, MessageTypes::Initialization); + + //write requester ID + buffer.insert(buffer.end(), reinterpret_cast(&requesterID), reinterpret_cast(&requesterID) + sizeof(requesterID)); + + + //write size of data chunk + buffer.insert(buffer.end(), reinterpret_cast(&totlen), reinterpret_cast(&totlen) + sizeof(totlen)); + + //write number of scripts + buffer.insert(buffer.end(), reinterpret_cast(&numScrips), reinterpret_cast(&numScrips) + sizeof(numScrips)); + + //write all scripts and their lengths + buffer.insert(buffer.end(), scriptMsg.begin(), scriptMsg.end()); + //send initialization message - queMessage(buffer); + queMessage(buffer); } void ParallelConnection::listenCommunication(){