int ClusterMembership::buildPacket(char *buf, int maxlen) { int l = 0; // Magic number *(unsigned int *) buf = htonl(MagicNumber); l += 4; // Cluster IP clusteraddr.copyTo(& (buf[l])); l += 4; // Our IP localaddr.copyTo(& (buf[l])); l += 4; bool ismaster = (localaddr == master); CommandType cmd = CommandStatus; if (ismaster) { cmd = CommandMaster; } // Command type *(unsigned int *) & buf[l] = htonl(cmd); l += 4; // Node weight *(int *) & buf[l] = htonl(effectiveWeight); l += 4; // If we're the master, add the number of nodes // followed by their limits... if (ismaster) { calcBoundaries(); int nodenumOffset = l; // Reserve a byte for num nodes l = l + 1; int numnodes = 0; for (IpNodeMap::iterator i=nodes.begin(); i != nodes.end(); i++) { if (l > (maxlen - 16)) { throw std::runtime_error("Buffer is in danger of overflow"); } const IpAddress & ip = (*i).first; NodeInfo &ni = (*i).second; if (ni.isup && (ni.upperHashLimit != 0)) { ip.copyTo(& (buf[l])); l += 4; *(int *) & buf[l] = htonl(ni.lowerHashLimit); l += 4; *(int *) & buf[l] = htonl(ni.upperHashLimit); l += 4; numnodes ++; } } // Add number of nodes. buf[nodenumOffset] = (char) numnodes; } return l; }
MultiVariableInterp2D::MultiVariableInterp2D(const char* fileName) { loadPoints(fileName); calcBoundaries(); }