sdbusplus:通过协程async_send异步调用service的method

通过async_send也可以完成协程调用:

//async_send.cpp
#include 
#include 
#include 
#include 
#include 

using namespace std;
using namespace sdbusplus;

void asyncCallSendYield(shared_ptr conn, boost::asio::yield_context yield)
{
    cout<<"1 async_send yield begin"<new_method_call("calculate.service", "/calculate_obj", "calculate_infterface.data", "AddInt");
    mesg1.append(1, 2);
    sdbusplus::message_t ret1 = conn->async_send(mesg1, yield[ec1]);
    int data1 = 0;
    ret1.read(data1);
    cout<<"ret data="<new_method_call("calculate.service", "/calculate_obj", "calculate_infterface.data", "AddInt");
    mesg2.append(3, 4);
    sdbusplus::message_t ret2 = conn->async_send(mesg2, yield[ec2]);
    int data2 = 0;
    ret2.read(data2);
    cout<<"ret data="<(io);
    cout<<"asyncCallSend begin"<
编译程序:
g++ -o async_send ./async_send.cpp -lsdbusplus -lsystemd -lboost_coroutine
运行程序输出:
asyncCallSend begin
asyncCallSend end
1 async_send yield begin
ret data=3
2 async_send yield end
3 async_send yield begin
ret data=7
4 async_send yield end

调用顺序与通过yield_method_call方式的协程调用是一样的:

sdbusplus:通过协程yield_method_call异步调用service的method_风静如云的博客-CSDN博客

你可能感兴趣的:(#,sdbusplus,linux)