本文整理汇总了C++中Coroutine::getResumeParam方法的典型用法代码示例。如果您正苦于以下问题:C++ Coroutine::getResumeParam方法的具体用法?C++ Coroutine::getResumeParam怎么用?C++ Coroutine::getResumeParam使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Coroutine
的用法示例。
在下文中一共展示了Coroutine::getResumeParam方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: rpc
/** rpc **/
Object* CoroutineService::rpc(const int64_t who, const int64_t to, const int64_t cmd, const int64_t res_proto_grp_id, Object* req_param){
if(to == getId()){
ERROR("service %s(%lld) can't request self", name(), (long long)m_id);
return 0;
}
// prepare
Coroutine* cr =Coroutine::Running();
if(!cr){
WARN("service %s(%lld) %lld fail to rpc to %lld, in main thread", name(), (long long)m_id, (long long)who, (long long)to);
return 0;
}
ASSERT(cr->canYield());
const int64_t cr_id =cr->getId();
// set rpc info
CoroutineRpcInfo* rpc_info =SafeNew<CoroutineRpcInfo>(res_proto_grp_id, cr_id);
if(!set_rpc(rpc_info)){
return 0;
}
const int64_t rpc_id =rpc_info->getId();
// prepare packet
PACKET packet;
packet.from =getId();
packet.to =to;
packet.who =who;
packet.sn =rpc_id;
packet.command =cmd;
packet.option =0;
// request
if(!DispatcherManager::RequestByObject(this, packet, req_param)){
WARN("service %s(%lld) %lld fail to rpc to %lld, service not ready", name(), (long long)m_id, (long long)who, (long long)to);
return 0;
}
rpc_info->set(rpc_id, this);
ENSURE(cr->yield(0, rpc_id));
// process respond
if(Command* respond =dynamic_cast< Command* >(cr->getResumeParam())){
// prepare
const PACKET res_packet =respond->getPacket();
if(res_packet.sn != static_cast<uint64_t>(rpc_id)){
WARN("service %s(%lld) %lld fail to rpc to %lld, rpc id mismatch", name(), (long long)m_id, (long long)who, (long long)to);
return 0;
}
// body is object pointer
if(res_packet.option & OPT_BODY_IS_OBJECT_POINTER){
return respond;
}
// body is protocol
if(res_proto_grp_id>0){
Bytes* res_bs =respond->getBody();
const int64_t res_cmd =static_cast<int64_t>(res_packet.command);
const int64_t group_id =res_proto_grp_id;
const int64_t protocol_id =res_cmd;
ProtocolBase* res_proto = ProtocolManager::CreateProtocol(group_id, protocol_id);
if(!res_proto){
ERROR("service %s(%lld) %lld fail to rpc to %lld, create protocol group %lld id %lld error", name(), (long long)m_id, (long long)who, (long long)to, (long long)group_id, (long long)protocol_id);
return 0;
}
if(!res_proto->fromBytes(res_bs)){
ERROR("service %s(%lld) %lld fail to rpc to %lld, unmarshal protocol name %s group %lld id %lld error", name(), (long long)m_id, (long long)who, (long long)to, res_proto->name(), (long long)group_id, (long long)protocol_id);
return 0;
}
respond->setRequest(res_proto);
}
// body is not special
return respond;
}
else{
return cr->getResumeParam();
}
}