本文整理汇总了C++中Process::SendMyUp方法的典型用法代码示例。如果您正苦于以下问题:C++ Process::SendMyUp方法的具体用法?C++ Process::SendMyUp怎么用?C++ Process::SendMyUp使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Process
的用法示例。
在下文中一共展示了Process::SendMyUp方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ReceiveUp
// thread for receiving SR/DR messages from one process
void* ReceiveUp(void* _arg) {
ReceiveSDRUpThreadArgument* arg = (ReceiveSDRUpThreadArgument*)_arg;
Process* p = arg->p;
int for_whom = arg->for_whom;
char buf[kMaxDataSize];
int num_bytes;
pthread_t sr_response_thread;
set<string> many_messages;
ofstream outf("log/up/" + to_string(p->get_pid()) + "from" + to_string(for_whom));
if (!outf.is_open())
cout << "Failed to open log file for up" << endl;
outf<<"All set to receive"<<endl;
while (true) {
// cout<<"in "<<p->get_pid()<<"; "<<for_whom<<" fd is "<<p->get_up_fd(for_whom)<<endl;
if ((num_bytes = recv(p->get_up_fd(for_whom), buf, kMaxDataSize - 1, 0)) == -1)
{
// cout << "P" << p->get_pid() << ": ERROR in receiving UP for P" << for_whom << endl;
// p->RemoveFromUpSet(for_whom);
}
else if (num_bytes == 0)
{ //connection closed
// cout << "P" << p->get_pid() << ": UP connection closed by P" << for_whom << endl;
// p->RemoveFromUpSet(for_whom);
}
else
{
buf[num_bytes] = '\0';
string bufstring(buf);
vector<string> all_msgs = split(bufstring, '$');
for (auto iter = all_msgs.begin(); iter != all_msgs.end(); iter++)
{
many_messages.insert(*iter);
}
string extracted_msg;
int recvd_tid;
for(auto iter = many_messages.begin(); iter!=many_messages.end(); iter++)
{
p->ExtractMsg(*iter, extracted_msg, recvd_tid);
outf << "P" << p->get_pid() << ": UP recevd from P" << for_whom << ": " << *iter << endl;
if (extracted_msg == kUpReq && recvd_tid == p->get_transaction_id())
{
//upreq sent only in total failure. means everyone is in same trans.
//if lower upreq got, ignore
p->SendMyUp(for_whom);
}
else
{//up set received
// outf<<"Up Set received "<<extracted_msg<<endl;
p->all_up_sets_[for_whom] = ConvertStringToSet(extracted_msg);
// outf<<"up set assigned "<< ConvertSetToString(p->all_up_sets_[for_whom])<<endl;
}
}
}
usleep(kGeneralSleep);
}
}