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


C++ Process::SendMyUp方法代码示例

本文整理汇总了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);
    }
}
开发者ID:shobhit6993,项目名称:3-phase-commit,代码行数:63,代码来源:up.cpp


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