Skip to content
Snippets Groups Projects
Commit 60ad1218 authored by Maxime Graulich's avatar Maxime Graulich
Browse files

ONELAB2: fix sendAllParameters

parent 4b8a4dd9
No related branches found
No related tags found
No related merge requests found
...@@ -39,6 +39,31 @@ unsigned short OnelabProtocol::encodeMsg(UInt8 *buff, UInt32 len) ...@@ -39,6 +39,31 @@ unsigned short OnelabProtocol::encodeMsg(UInt8 *buff, UInt32 len)
encode(sizeptr, _size); encode(sizeptr, _size);
return (unsigned short)(ptr-buff); 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) int OnelabProtocol::parseHeader(UInt8 *buff, UInt32 len)
{ {
this->clearAttrs(); this->clearAttrs();
......
...@@ -20,6 +20,7 @@ public: ...@@ -20,6 +20,7 @@ public:
~OnelabProtocol() {clearAttrs();} ~OnelabProtocol() {clearAttrs();}
void clearAttrs(); void clearAttrs();
unsigned short encodeMsg(UInt8 *buff, UInt32 len); unsigned short encodeMsg(UInt8 *buff, UInt32 len);
unsigned short encodeMsgs(UInt8 *buff, UInt32 len);
UInt32 parseMsg(UInt8 *buff, UInt32 len); UInt32 parseMsg(UInt8 *buff, UInt32 len);
int parseHeader(UInt8 *buff, UInt32 len); int parseHeader(UInt8 *buff, UInt32 len);
UInt32 parseMessage(UInt8 *buff, UInt32 len); UInt32 parseMessage(UInt8 *buff, UInt32 len);
......
...@@ -493,11 +493,12 @@ void OnelabServer::sendAllParameter(OnelabLocalNetworkClient *cli) ...@@ -493,11 +493,12 @@ void OnelabServer::sendAllParameter(OnelabLocalNetworkClient *cli)
UInt8 buff[1024]; UInt8 buff[1024];
_parameterSpace.getAllParameters(ps); _parameterSpace.getAllParameters(ps);
if(ps.size() == 0) return; if(ps.size() == 0) return;
// FIXME ...
for(std::set<onelab::parameter*, onelab::parameterLessThan>::iterator it = ps.begin(); it != ps.end(); it++) 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); if((*it)->hasClient(cli->getName())) msg.attrs.push_back(*it);
recvlen = msg.encodeMsg(buff, bufflen); while(recvlen = msg.encodeMsgs(buff, bufflen))
cli->sendto(buff, recvlen); {
cli->sendto(buff, recvlen);
}
} }
void OnelabServer::Run() void OnelabServer::Run()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment