diff --git a/contrib/onelab2/OnelabProtocol.cpp b/contrib/onelab2/OnelabProtocol.cpp index 962ec1578c60367f6cee652a4b14d379b3f4ec90..d8b3d3198f546fc6bd2ff9288481d60525e51fae 100644 --- a/contrib/onelab2/OnelabProtocol.cpp +++ b/contrib/onelab2/OnelabProtocol.cpp @@ -39,6 +39,31 @@ unsigned short OnelabProtocol::encodeMsg(UInt8 *buff, UInt32 len) encode(sizeptr, _size); return (unsigned short)(ptr-buff); } +unsigned short OnelabProtocol::encodeMsgs(UInt8 *buff, UInt32 len) +{ + if(len < 4) throw ERROR_BUFFER_TOO_SMALL; + if(!attrs.size()) return 0; + UInt8 *ptr = encode(buff, (UInt8)ONELAB_VERSION); + ptr = encode(ptr, _type); + UInt8 *sizeptr = ptr; + _size = 0; + ptr = encode(sizeptr, _size); + while(attrs.size() > 0) { + OnelabAttr *attr = attrs.back(); + UInt16 attrLen = attr->getAttributeLength(); + if(4+_size+attrLen > len) { + encode(sizeptr, _size); + return (unsigned short)(ptr-buff); + } + ptr = attr->encodeAttribute(ptr); + if(!attr->isInDatabase()) delete attr; + attrs.pop_back(); + _size+=attrLen+4; + } + + encode(sizeptr, _size); + return (unsigned short)(ptr-buff); +} int OnelabProtocol::parseHeader(UInt8 *buff, UInt32 len) { this->clearAttrs(); diff --git a/contrib/onelab2/OnelabProtocol.h b/contrib/onelab2/OnelabProtocol.h index 1380da79b6df1ac8e4011de3c4842ab4aefcc78d..f8ca685e81aab6a96f21bb7199b2e3741e17a0f0 100644 --- a/contrib/onelab2/OnelabProtocol.h +++ b/contrib/onelab2/OnelabProtocol.h @@ -20,6 +20,7 @@ public: ~OnelabProtocol() {clearAttrs();} void clearAttrs(); unsigned short encodeMsg(UInt8 *buff, UInt32 len); + unsigned short encodeMsgs(UInt8 *buff, UInt32 len); UInt32 parseMsg(UInt8 *buff, UInt32 len); int parseHeader(UInt8 *buff, UInt32 len); UInt32 parseMessage(UInt8 *buff, UInt32 len); diff --git a/contrib/onelab2/OnelabServer.cpp b/contrib/onelab2/OnelabServer.cpp index ce6ae8087d8ede9897919cea2da5feca050cac1f..9aabef7e200b44e06787a5bbedce037281be2ca7 100644 --- a/contrib/onelab2/OnelabServer.cpp +++ b/contrib/onelab2/OnelabServer.cpp @@ -493,11 +493,12 @@ void OnelabServer::sendAllParameter(OnelabLocalNetworkClient *cli) UInt8 buff[1024]; _parameterSpace.getAllParameters(ps); if(ps.size() == 0) return; - // FIXME ... for(std::set<onelab::parameter*, onelab::parameterLessThan>::iterator it = ps.begin(); it != ps.end(); it++) if((*it)->hasClient(cli->getName())) msg.attrs.push_back(*it); - recvlen = msg.encodeMsg(buff, bufflen); - cli->sendto(buff, recvlen); + while(recvlen = msg.encodeMsgs(buff, bufflen)) + { + cli->sendto(buff, recvlen); + } } void OnelabServer::Run()