RFoe / coasync

Asynchronous network library that supports coroutines in C++20
https://github.com/RFoe/coasync
MIT License
51 stars 5 forks source link

完善rpc功能 #3

Open RFoe opened 2 months ago

RFoe commented 2 months ago

https://github.com/RFoe/coasync/blob/a466688370ce4bc5feefc8a55d960de447dfbfde/include/coasync/net/rpc/rpc_client.hpp#L10 https://github.com/RFoe/coasync/blob/a466688370ce4bc5feefc8a55d960de447dfbfde/include/coasync/net/rpc/rpc_server.hpp#L21

rpc功能还是过于简单

co_await client.call("add", 888, 999) | on_error([](std::error_code& ec) {...;});

+ 优雅的抑制响应/断开连接
```cpp
// common definition
enum option_set {
    suppress_response_requested = 0,
    shut_down_requested,
}
// server side
rpc_server.bind("generic_control", [] (net::rpc::control_token token, int option) -> void
{
    if(option == shut_down_requested) token.request_close();
    else if (option == shut_down_requested) token.request_noresponse();
    return;
});
// client side
co_await rpc_client.call_nonblock<void>("generic_control", option_set::suppress_response_requested);
co_await rpc_client.call_nonblock<void>("generic_control", option_set::shut_down_requested);