本文整理汇总了C++中SectorMsg::resize方法的典型用法代码示例。如果您正苦于以下问题:C++ SectorMsg::resize方法的具体用法?C++ SectorMsg::resize怎么用?C++ SectorMsg::resize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SectorMsg
的用法示例。
在下文中一共展示了SectorMsg::resize方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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();
}
示例2: recvmsg
int SSLTransport::recvmsg(SectorMsg& msg)
{
if (recv((char*)&msg.m_iDataLength, 4) < 0)
return -1;
cout << "recv " << msg.m_iDataLength << endl;
msg.resize(msg.m_iDataLength);
if (recv(msg.m_pcBuffer, msg.m_iDataLength) < 0)
return -1;
return msg.m_iDataLength;
}
示例3: run
void Slave::run()
{
string ip;
int port;
int32_t id;
SectorMsg* msg = new SectorMsg;
msg->resize(65536);
cout << "slave process: " << "GMP " << m_iLocalPort << " DATA " << m_DataChn.getPort() << endl;
while (true)
{
if (m_GMP.recvfrom(ip, port, id, msg) < 0)
break;
cout << "recv cmd " << ip << " " << port << " type " << msg->getType() << endl;
// a slave only accepts commands from the masters
Address addr;
addr.m_strIP = ip;
addr.m_iPort = port;
if (m_Routing.getRouterID(addr) < 0)
continue;
switch (msg->getType() / 100)
{
case 0:
processSysCmd(ip, port, id, msg);
break;
case 1:
processFSCmd(ip, port, id, msg);
break;
case 2:
processDCCmd(ip, port, id, msg);
break;
case 10:
processMCmd(ip, port, id, msg);
break;
default:
break;
}
}
delete msg;
}
示例4: 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;
}
示例5: run
void Slave::run()
{
string ip;
int port;
int32_t id;
SectorMsg* msg = new SectorMsg;
msg->resize(65536);
cout << "slave process: " << "GMP " << m_iLocalPort << " DATA " << m_DataChn.getPort() << endl;
m_bRunning = true;
pthread_t worker_thread;
#ifndef WIN32 // <slr>
pthread_create(&worker_thread, NULL, worker, this);
#else
unsigned int ThreadID;
worker_thread = (HANDLE)_beginthreadex(NULL, 0, worker, this, NULL, &ThreadID);
#endif
while (m_bRunning)
{
if (m_GMP.recvfrom(ip, port, id, msg) < 0)
break;
m_SectorLog << LogStringTag(LogTag::START, LogLevel::SCREEN) << "recv cmd " << ip << " " << port << " type " << msg->getType() << LogStringTag(LogTag::END);
// a slave only accepts commands from the masters
Address addr;
addr.m_strIP = ip;
addr.m_iPort = port;
if (m_Routing.getRouterID(addr) < 0)
continue;
switch (msg->getType() / 100)
{
case 0:
processSysCmd(ip, port, id, msg);
break;
case 1:
processFSCmd(ip, port, id, msg);
break;
case 2:
processDCCmd(ip, port, id, msg);
break;
case 3:
processDBCmd(ip, port, id, msg);
break;
case 10:
processMCmd(ip, port, id, msg);
break;
#ifdef DEBUG
processDebugCmd(ip, port, id, msg);
break;
#endif
default:
break;
}
}
delete msg;
#ifndef WIN32
pthread_join(worker_thread, NULL);
#else
WaitForSingleObject(worker_thread, INFINITE);
#endif
// TODO: check and cancel all file&spe threads
cout << "slave is stopped by master\n";
}