rpclib
rpclib copied to clipboard
Terminating the server via RPC call
Hi. I am not sure if it's a bug or my misunderstanding of documentation. I would like to terminate a process via rpc message. Now,the thing is ,there is rpc server loop which needs to be closed,right?
So I wrote a message handler like this:
```
rpc::server srv(rpc::constants::DEFAULT_PORT); //Process terminate callback srv.bind("close", { rpc::this_server_t server = rpc::this_server(); server.stop(); return 1; });
Because a comment for rpc::this_server() states "A thread-local object that can be used to control
the behavior of the server w.r.t. the handler." ,I assumed that I can use it to terminate the server and exit its loop.But that never happens.
That should work, it is unit tested. Would you try running the unit tests in your environment and report back? Call cmake with -DRPCLIB_BUILD_TESTS=ON
.
Can you point me to the place you test it in your tests?Maybe I do it wrong. I am not building your lib on Linux with CMake and it's a pain in the ass for me now to start reconfigure it.Thanks.
It's here: https://github.com/rpclib/rpclib/blob/master/tests/rpc/this_server_test.cc#L28
Well.I am not sure your test case is like my use case.
Here is what I do:
```
rpc::server srv(rpc::constants::DEFAULT_PORT); srv.bind("close", { rpc::this_server_t sserver = rpc::this_server(); sserver.stop(); return 1; }); srv.run();
And then I call from a client which is somewhere outside the program (using python rpc).
What happens is that src.run() doesn't exit from the blocking.
Yeah, this sounds like a bug. I'll look into it.
Hi. I am just checking,the bug is still open,right? Mike.
Hi Mike,
Yes, sorry to say I didn't yet have time to look into it.
Happens to me too, run() does not exit from blocking.
Working around it temporarily with a nasty hack.
rpc::server rpc_server(port);
std::atomic<bool> stop = false;
... bind callbacks
rpc_server.async_run();
do {
std::this_thread::sleep_for(std::chrono::milliseconds(10));
} while (!stop);
Same problem here. I hope this bug will get fixed.