当前位置: 首页>>代码示例>>C++>>正文


C++ SectorMsg::setKey方法代码示例

本文整理汇总了C++中SectorMsg::setKey方法的典型用法代码示例。如果您正苦于以下问题:C++ SectorMsg::setKey方法的具体用法?C++ SectorMsg::setKey怎么用?C++ SectorMsg::setKey使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在SectorMsg的用法示例。


在下文中一共展示了SectorMsg::setKey方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: sysinfo

int Client::sysinfo(SysStat& sys)
{
   SectorMsg msg;
   msg.setKey(m_iKey);
   msg.setType(3);
   msg.m_iDataLength = SectorMsg::m_iHdrSize;

   Address serv;
   m_Routing.lookup(m_iKey, serv);
   login(serv.m_strIP, serv.m_iPort);

   if (m_GMP.rpc(serv.m_strIP.c_str(), serv.m_iPort, &msg, &msg) < 0)
      return SectorError::E_CONNECTION;

   if (msg.getType() < 0)
      return *(int32_t*)(msg.getData());

   deserializeSysStat(sys, msg.getData(), msg.m_iDataLength);

   for (vector<Address>::iterator i = sys.m_vMasterList.begin(); i != sys.m_vMasterList.end(); ++ i)
   {
      if (i->m_strIP.length() == 0)
      {
         i->m_strIP = serv.m_strIP;
         break;
      }
   }

   return 0;
}
开发者ID:besquared,项目名称:sector-sphere,代码行数:30,代码来源:client.cpp

示例2: keepAlive

void* Client::keepAlive(void* param)
{
   Client* self = (Client*)param;

   while (self->m_bActive)
   {
      timeval t;
      gettimeofday(&t, NULL);
      timespec ts;
      ts.tv_sec  = t.tv_sec + 60 * 10;
      ts.tv_nsec = t.tv_usec * 1000;

      pthread_mutex_lock(&self->m_KALock);
      pthread_cond_timedwait(&self->m_KACond, &self->m_KALock, &ts);
      pthread_mutex_unlock(&self->m_KALock);

      if (!self->m_bActive)
      {
         break;
      }

      for (set<Address, AddrComp>::iterator i = self->m_sMasters.begin(); i != self->m_sMasters.end(); ++ i)
      {
         // send keep-alive msg to each logged in master
         SectorMsg msg;
         msg.setKey(self->m_iKey);
         msg.setType(6);
         msg.m_iDataLength = SectorMsg::m_iHdrSize;
         self->m_GMP.rpc(i->m_strIP.c_str(), i->m_iPort, &msg, &msg);
      }
   }

   return NULL;
}
开发者ID:besquared,项目名称:sector-sphere,代码行数:34,代码来源:client.cpp

示例3: list

int Client::list(const string& path, vector<SNode>& attr)
{
   string revised_path = Metadata::revisePath(path);

   SectorMsg msg;
   msg.resize(65536);
   msg.setType(101);
   msg.setKey(m_iKey);
   msg.setData(0, revised_path.c_str(), revised_path.length() + 1);

   Address serv;
   m_Routing.lookup(revised_path, serv);
   login(serv.m_strIP, serv.m_iPort);

   if (m_GMP.rpc(serv.m_strIP.c_str(), serv.m_iPort, &msg, &msg) < 0)
      return SectorError::E_CONNECTION;

   if (msg.getType() < 0)
      return *(int32_t*)(msg.getData());

   string filelist = msg.getData();

   unsigned int s = 0;
   while (s < filelist.length())
   {
      int t = filelist.find(';', s);
      SNode sn;
      sn.deserialize(filelist.substr(s, t - s).c_str());
      attr.insert(attr.end(), sn);
      s = t + 1;
   }

   return attr.size();
}
开发者ID:besquared,项目名称:sector-sphere,代码行数:34,代码来源:client.cpp

示例4: reportSphere

int Slave::reportSphere(const string& master_ip, const int& master_port, const int& transid, const vector<Address>* bad)
{
   SectorMsg msg;
   msg.setType(4);
   msg.setKey(0);
   msg.setData(0, (char*)&transid, 4);
   msg.setData(4, (char*)&m_iSlaveID, 4);

   int num = (NULL == bad) ? 0 : bad->size();
   msg.setData(8, (char*)&num, 4);
   for (int i = 0; i < num; ++ i)
   {
      msg.setData(12 + 68 * i, (*bad)[i].m_strIP.c_str(), (*bad)[i].m_strIP.length() + 1);
      msg.setData(12 + 68 * i + 64, (char*)&((*bad)[i].m_iPort), 4);
   }

   cout << "reportSphere " << master_ip << " " << master_port << " " << transid << endl;

   if (m_GMP.rpc(master_ip.c_str(), master_port, &msg, &msg) < 0)
      return -1;

   if (msg.getType() < 0)
      return *(int32_t*)msg.getData();

   return 1;
}
开发者ID:norouzi4d,项目名称:sector,代码行数:26,代码来源:slave.cpp

示例5: move

int Client::move(const string& oldpath, const string& newpath)
{
   string src = Metadata::revisePath(oldpath);
   string dst = Metadata::revisePath(newpath);

   SectorMsg msg;
   msg.setType(104);
   msg.setKey(m_iKey);

   int32_t size = src.length() + 1;
   msg.setData(0, (char*)&size, 4);
   msg.setData(4, src.c_str(), src.length() + 1);
   size = dst.length() + 1;
   msg.setData(4 + src.length() + 1, (char*)&size, 4);
   msg.setData(4 + src.length() + 1 + 4, dst.c_str(), dst.length() + 1);

   Address serv;
   m_Routing.lookup(src, serv);
   login(serv.m_strIP, serv.m_iPort);

   if (m_GMP.rpc(serv.m_strIP.c_str(), serv.m_iPort, &msg, &msg) < 0)
      return SectorError::E_CONNECTION;

   if (msg.getType() < 0)
      return *(int32_t*)(msg.getData());

   return 0;
}
开发者ID:besquared,项目名称:sector-sphere,代码行数:28,代码来源:client.cpp

示例6: copy

int Client::copy(const string& src, const string& dst)
{
   string rsrc = Metadata::revisePath(src);
   string rdst = Metadata::revisePath(dst);

   SectorMsg msg;
   msg.setType(106);
   msg.setKey(m_iKey);

   int32_t size = rsrc.length() + 1;
   msg.setData(0, (char*)&size, 4);
   msg.setData(4, rsrc.c_str(), rsrc.length() + 1);
   size = rdst.length() + 1;
   msg.setData(4 + rsrc.length() + 1, (char*)&size, 4);
   msg.setData(4 + rsrc.length() + 1 + 4, rdst.c_str(), rdst.length() + 1);

   Address serv;
   m_Routing.lookup(rsrc, serv);
   login(serv.m_strIP, serv.m_iPort);

   if (m_GMP.rpc(serv.m_strIP.c_str(), serv.m_iPort, &msg, &msg) < 0)
      return SectorError::E_CONNECTION;

   if (msg.getType() < 0)
      return *(int32_t*)(msg.getData());

   return 0;
}
开发者ID:besquared,项目名称:sector-sphere,代码行数:28,代码来源:client.cpp

示例7: report

int Slave::report(const string& master_ip, const int& master_port, const int32_t& transid, const vector<string>& filelist, const int& change)
{
   vector<string> serlist;
   for (vector<string>::const_iterator i = filelist.begin(); i != filelist.end(); ++ i)
   {
      struct stat s;
      if (-1 == stat((m_strHomeDir + *i).c_str(), &s))
         continue;

      SNode sn;
      sn.m_strName = *i;
      sn.m_bIsDir = S_ISDIR(s.st_mode) ? 1 : 0;
      sn.m_llTimeStamp = s.st_mtime;
      sn.m_llSize = s.st_size;

      char buf[1024];
      sn.serialize(buf);

      //update local
      Address addr;
      addr.m_strIP = "127.0.0.1";
      addr.m_iPort = 0;
      m_pLocalFile->update(buf, addr, change);

      serlist.push_back(buf);
   }

   if (serlist.empty())
      return 0;

   SectorMsg msg;
   msg.setType(1);
   msg.setKey(0);
   msg.setData(0, (char*)&transid, 4);
   msg.setData(4, (char*)&m_iSlaveID, 4);
   msg.setData(8, (char*)&change, 4);
   int32_t num = serlist.size();
   msg.setData(12, (char*)&num, 4);
   int pos = 16;
   for (vector<string>::iterator i = serlist.begin(); i != serlist.end(); ++ i)
   {
      int32_t bufsize = i->length() + 1;
      msg.setData(pos, (char*)&bufsize, 4);
      msg.setData(pos + 4, i->c_str(), bufsize);
      pos += bufsize + 4;
   }

   cout << "report " << master_ip << " " << master_port << " " << num << endl;

   if (m_GMP.rpc(master_ip.c_str(), master_port, &msg, &msg) < 0)
      return -1;

   if (msg.getType() < 0)
      return *(int32_t*)msg.getData();

   return 1;
}
开发者ID:norouzi4d,项目名称:sector,代码行数:57,代码来源:slave.cpp

示例8: connectSPE

int DCClient::connectSPE(SPE& s)
{
   if (s.m_iStatus != 0)
      return -1;

   SectorMsg msg;
   msg.setType(203); // start processing engine
   msg.setKey(m_pClient->m_iKey);
   msg.setData(0, s.m_strIP.c_str(), s.m_strIP.length() + 1);
   msg.setData(64, (char*)&(s.m_iPort), 4);
   // leave a 4-byte blank spot for data port
   msg.setData(72, (char*)&(s.m_iID), 4);
   msg.setData(76, (char*)&m_pClient->m_iKey, 4);
   msg.setData(80, m_strOperator.c_str(), m_strOperator.length() + 1);
   int offset = 80 + m_strOperator.length() + 1;
   msg.setData(offset, (char*)&m_iRows, 4);
   msg.setData(offset + 4, (char*)&m_iParamSize, 4);
   msg.setData(offset + 8, m_pcParam, m_iParamSize);
   offset += 4 + 8 + m_iParamSize;
   msg.setData(offset, (char*)&m_iProcType, 4);

   Address serv;
   m_pClient->m_Routing.getPrimaryMaster(serv);
   if ((m_pClient->m_GMP.rpc(serv.m_strIP.c_str(), serv.m_iPort, &msg, &msg) < 0) || (msg.getType() < 0))
      return SectorError::E_CONNECTION;

   s.m_iSession = *(int32_t*)msg.getData();

   m_pClient->m_DataChn.connect(s.m_strIP, s.m_iDataPort);

   cout << "connect SPE " << s.m_strIP.c_str() << " " << *(int*)(msg.getData()) << endl;

   // send output information
   m_pClient->m_DataChn.send(s.m_strIP, s.m_iDataPort, s.m_iSession, (char*)&m_iOutputType, 4);
   if (m_iOutputType > 0)
   {
      int bnum = m_mBucket.size();
      m_pClient->m_DataChn.send(s.m_strIP, s.m_iDataPort, s.m_iSession, (char*)&bnum, 4);
      m_pClient->m_DataChn.send(s.m_strIP, s.m_iDataPort, s.m_iSession, m_pOutputLoc, bnum * 80);
      m_pClient->m_DataChn.send(s.m_strIP, s.m_iDataPort, s.m_iSession, (char*)m_pOutput->m_piLocID, m_iOutputType * 4);
   }
   else if (m_iOutputType < 0)
      m_pClient->m_DataChn.send(s.m_strIP, s.m_iDataPort, s.m_iSession, m_pOutputLoc, strlen(m_pOutputLoc) + 1);

   loadOperator(s.m_strIP, s.m_iPort, s.m_iDataPort, s.m_iSession);

   s.m_iStatus = 1;

   return 0;
}
开发者ID:norouzi4d,项目名称:sector,代码行数:50,代码来源:dcclient.cpp

示例9: logout

int Client::logout()
{
   for (set<Address, AddrComp>::iterator i = m_sMasters.begin(); i != m_sMasters.end(); ++ i)
   {
      SectorMsg msg;
      msg.setKey(m_iKey);
      msg.setType(2);
      msg.m_iDataLength = SectorMsg::m_iHdrSize;
      m_GMP.rpc(i->m_strIP.c_str(), i->m_iPort, &msg, &msg);
   }

   m_sMasters.clear();

   m_iKey = 0;
   return 0;
}
开发者ID:besquared,项目名称:sector-sphere,代码行数:16,代码来源:client.cpp

示例10: reopen

int FSClient::reopen()
{
   if (0 == m_strFileName.length())
      return -1;

   // currently re-open only works on read
   if (m_bWrite)
      return -1;

   // close connection to the current slave
   int32_t cmd = 5;
   m_pClient->m_DataChn.send(m_strSlaveIP, m_iSlaveDataPort, m_iSession, (char*)&cmd, 4);
   int response;
   m_pClient->m_DataChn.recv4(m_strSlaveIP, m_iSlaveDataPort, m_iSession, response);
   m_pClient->m_DataChn.remove(m_strSlaveIP, m_iSlaveDataPort);


   SectorMsg msg;
   msg.setType(112); // open the file
   msg.setKey(m_pClient->m_iKey);
   msg.setData(0, (char*)&m_iSession, 4);
   int32_t port = m_pClient->m_DataChn.getPort();
   msg.setData(4, (char*)&port, 4);

   Address serv;
   m_pClient->lookup(m_strFileName, serv);
   if (m_pClient->m_GMP.rpc(serv.m_strIP.c_str(), serv.m_iPort, &msg, &msg) < 0)
      return SectorError::E_CONNECTION;

   if (msg.getType() < 0)
      return *(int32_t*)(msg.getData());

   m_strSlaveIP = msg.getData();
   m_iSlaveDataPort = *(int*)(msg.getData() + 64);

   if (m_pClient->m_DataChn.connect(m_strSlaveIP, m_iSlaveDataPort) < 0)
      return SectorError::E_CONNECTION;

   memcpy(m_pcKey, m_pClient->m_pcCryptoKey, 16);
   memcpy(m_pcIV, m_pClient->m_pcCryptoIV, 8);
   m_pClient->m_DataChn.setCryptoKey(m_strSlaveIP, m_iSlaveDataPort, m_pcKey, m_pcIV);

   return 0;
}
开发者ID:heshucheng,项目名称:sector,代码行数:44,代码来源:fsclient.cpp

示例11: updateMasters

int Client::updateMasters()
{
   SectorMsg msg;
   msg.setKey(m_iKey);

   map<uint32_t, Address> al;
   m_Routing.getListOfMasters(al);
   for (map<uint32_t, Address>::iterator i = al.begin(); i != al.end(); ++ i)
   {
      msg.setType(5);

      if (m_GMP.rpc(i->second.m_strIP.c_str(), i->second.m_iPort, &msg, &msg) >= 0)
      {
         Address addr;
         addr.m_strIP = i->second.m_strIP;
         addr.m_iPort = i->second.m_iPort;
         uint32_t key = i->first;
         
         m_Routing.init();
         m_Routing.insert(key, addr);

         int n = *(int32_t*)msg.getData();
         int p = 4;
         for (int m = 0; m < n; ++ m)
         {
            key = *(int32_t*)(msg.getData() + p);
            p += 4;
            addr.m_strIP = msg.getData() + p;
            p += addr.m_strIP.length() + 1;
            addr.m_iPort = *(int32_t*)(msg.getData() + p);
            p += 4;

            m_Routing.insert(key, addr);
         }

         return n + 1;
      }
   }

   return -1;
}
开发者ID:besquared,项目名称:sector-sphere,代码行数:41,代码来源:client.cpp

示例12: remove

int Client::remove(const string& path)
{
   string revised_path = Metadata::revisePath(path);

   SectorMsg msg;
   msg.setType(105);
   msg.setKey(m_iKey);
   msg.setData(0, revised_path.c_str(), revised_path.length() + 1);

   Address serv;
   m_Routing.lookup(revised_path, serv);
   login(serv.m_strIP, serv.m_iPort);

   if (m_GMP.rpc(serv.m_strIP.c_str(), serv.m_iPort, &msg, &msg) < 0)
      return SectorError::E_CONNECTION;

   if (msg.getType() < 0)
      return *(int32_t*)(msg.getData());

   return 0;
}
开发者ID:besquared,项目名称:sector-sphere,代码行数:21,代码来源:client.cpp

示例13: dataInfo

int DCClient::dataInfo(const vector<string>& files, vector<string>& info)
{
   SectorMsg msg;
   msg.setType(201);
   msg.setKey(m_pClient->m_iKey);

   int offset = 0;
   int32_t size = -1;
   for (vector<string>::const_iterator i = files.begin(); i != files.end(); ++ i)
   {
      string path = Metadata::revisePath(*i);
      size = path.length() + 1;
      msg.setData(offset, (char*)&size, 4);
      msg.setData(offset + 4, path.c_str(), size);
      offset += 4 + size;
   }

   size = -1;
   msg.setData(offset, (char*)&size, 4);

   Address serv;
   m_pClient->m_Routing.getPrimaryMaster(serv);
   if (m_pClient->m_GMP.rpc(serv.m_strIP.c_str(), serv.m_iPort, &msg, &msg) < 0)
      return SectorError::E_CONNECTION;

   if (msg.getType() < 0)
      return *(int32_t*)(msg.getData());

   char* buf = msg.getData();
   size = msg.m_iDataLength - SectorMsg::m_iHdrSize;

   while (size > 0)
   {
      info.insert(info.end(), buf);
      size -= strlen(buf) + 1;
      buf += strlen(buf) + 1;
   }

   return info.size();
}
开发者ID:norouzi4d,项目名称:sector,代码行数:40,代码来源:dcclient.cpp

示例14: stat

int Client::stat(const string& path, SNode& attr)
{
   string revised_path = Metadata::revisePath(path);

   SectorMsg msg;
   msg.resize(65536);
   msg.setType(102);
   msg.setKey(m_iKey);
   msg.setData(0, revised_path.c_str(), revised_path.length() + 1);

   Address serv;
   m_Routing.lookup(revised_path, serv);
   login(serv.m_strIP, serv.m_iPort);

   if (m_GMP.rpc(serv.m_strIP.c_str(), serv.m_iPort, &msg, &msg) < 0)
      return SectorError::E_CONNECTION;

   if (msg.getType() < 0)
      return *(int32_t*)(msg.getData());

   attr.deserialize(msg.getData());

   int n = (msg.m_iDataLength - SectorMsg::m_iHdrSize - 128) / 68;
   char* al = msg.getData() + 128;

   for (int i = 0; i < n; ++ i)
   {
      Address addr;
      addr.m_strIP = al + 68 * i;
      addr.m_iPort = *(int32_t*)(al + 68 * i + 64);
      attr.m_sLocation.insert(addr);
   }

   // check local cache: updated files may not be sent to the master yet
   m_StatCache.stat(path, attr);

   return 0;
}
开发者ID:besquared,项目名称:sector-sphere,代码行数:38,代码来源:client.cpp

示例15: copy

void* Slave::copy(void* p)
{
   Slave* self = ((Param3*)p)->serv_instance;
   int transid = ((Param3*)p)->transid;
   string src = ((Param3*)p)->src;
   string dst = ((Param3*)p)->dst;
   string master_ip = ((Param3*)p)->master_ip;
   int master_port = ((Param3*)p)->master_port;
   delete (Param3*)p;

   if (src.c_str()[0] == '\0')
      src = "/" + src;
   if (dst.c_str()[0] == '\0')
      dst = "/" + dst;

   SNode tmp;
   if (self->m_pLocalFile->lookup(src.c_str(), tmp) >= 0)
   {
      //if file is local, copy directly
      //note that in this case, src != dst, therefore this is a regular "cp" command, not a system replication
      //TODO: check disk space

      self->createDir(dst.substr(0, dst.rfind('/')));
      string rhome = self->reviseSysCmdPath(self->m_strHomeDir);
      string rsrc = self->reviseSysCmdPath(src);
      string rdst = self->reviseSysCmdPath(dst);
      system(("cp " + rhome + rsrc + " " + rhome + rdst).c_str());

      // if the file has been modified during the replication, remove this replica
      int type = (src == dst) ? +FileChangeType::FILE_UPDATE_REPLICA : +FileChangeType::FILE_UPDATE_NEW;

      struct stat64 s;
      if (stat64((self->m_strHomeDir + dst).c_str(), &s) < 0)
         type = +FileChangeType::FILE_UPDATE_NO;

      if (self->report(master_ip, master_port, transid, dst, type) < 0)
         system(("rm " + rhome + rdst).c_str());

      // clear this transaction
      self->m_TransManager.updateSlave(transid, self->m_iSlaveID);

      return NULL;
   }

   bool success = true;

   queue<string> tr;
   tr.push(src);

   while (!tr.empty())
   {
      string src_path = tr.front();
      tr.pop();

      // try list this path
      SectorMsg msg;
      msg.setType(101);
      msg.setKey(0);
      msg.setData(0, src_path.c_str(), src_path.length() + 1);

      Address addr;
      self->m_Routing.lookup(src_path, addr);

      if (self->m_GMP.rpc(addr.m_strIP.c_str(), addr.m_iPort, &msg, &msg) < 0)
      {
         success = false;
         break;
      }

      if (msg.getType() >= 0)
      {
         // if this is a directory, put all files and sub-drectories into the queue of files to be copied

         string filelist = msg.getData();
         unsigned int s = 0;
         while (s < filelist.length())
         {
            int t = filelist.find(';', s);
            SNode sn;
            sn.deserialize(filelist.substr(s, t - s).c_str());
            tr.push(src_path + "/" + sn.m_strName);
            s = t + 1;
         }

         continue;
      }

      // open the file and copy it to local
      msg.setType(110);
      msg.setKey(0);

      int32_t mode = SF_MODE::READ;
      msg.setData(0, (char*)&mode, 4);
      int64_t reserve = 0;
      msg.setData(4, (char*)&reserve, 8);
      int32_t localport = self->m_DataChn.getPort();
      msg.setData(12, (char*)&localport, 4);
      msg.setData(16, "\0", 1);
      msg.setData(80, src_path.c_str(), src_path.length() + 1);

//.........这里部分代码省略.........
开发者ID:norouzi4d,项目名称:sector,代码行数:101,代码来源:serv_file.cpp


注:本文中的SectorMsg::setKey方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。