qicosmos / rest_rpc

modern C++(C++11), simple, easy to use rpc framework
MIT License
1.66k stars 365 forks source link

异步回调接口无法捕捉server退出的异常 #82

Closed Cai-Yao closed 1 year ago

Cai-Yao commented 1 year ago

rest_rpc里的异步回调接口,在用的时候server被关闭,使用示例代码设置超时的方式不能捕捉到这个错误

client:

void test_callback_add() {
    rpc_client client;
    bool r = client.connect("127.0.0.1", 9123);
    int cnt = 0;
    for (int i = 0; i < 1000; i++) {    
        client.async_call<500>("add", [&](asio::error_code ec, string_view data) {
            if (ec) {       
                cnt++;         
                std::cout << ec.message() << "\n";
                return;
            }
            auto result = as<int>(data);
            std::cout << result << "\n";
            cnt++;
        }, i, i);
    }
    while(cnt != 1000) {}
    client.stop();
}
qicosmos commented 1 year ago

已经fix了:https://github.com/qicosmos/rest_rpc/commit/5ad5f086c3385402e0840f6c8191a710c8bb90a4 拉一下代码测试一下。

Cai-Yao commented 1 year ago

嗯好,谢谢,现在可以了