mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-06-04 02:02:42 +02:00
ipc: Use EventLoopRef instead of addClient/removeClient
Use EventLoopRef to avoid reference counting bugs and be more exception safe and deal with removal of addClient/removeClient methods in https://github.com/bitcoin-core/libmultiprocess/pull/160 A test update is also required due to https://github.com/bitcoin-core/libmultiprocess/pull/160 to deal with changed reference count semantics. In IpcPipeTest(), it is now necessary to destroy the client Proxy object instead of just the client Connection object to decrease the event loop reference count and allow the loop to exit so the test does not hang on shutdown.
This commit is contained in:
@@ -55,7 +55,6 @@ void IpcPipeTest()
|
||||
{
|
||||
// Setup: create FooImplementation object and listen for FooInterface requests
|
||||
std::promise<std::unique_ptr<mp::ProxyClient<gen::FooInterface>>> foo_promise;
|
||||
std::function<void()> disconnect_client;
|
||||
std::thread thread([&]() {
|
||||
mp::EventLoop loop("IpcPipeTest", [](bool raise, const std::string& log) { LogPrintf("LOG%i: %s\n", raise, log); });
|
||||
auto pipe = loop.m_io_context.provider->newTwoWayPipe();
|
||||
@@ -63,9 +62,9 @@ void IpcPipeTest()
|
||||
auto connection_client = std::make_unique<mp::Connection>(loop, kj::mv(pipe.ends[0]));
|
||||
auto foo_client = std::make_unique<mp::ProxyClient<gen::FooInterface>>(
|
||||
connection_client->m_rpc_system->bootstrap(mp::ServerVatId().vat_id).castAs<gen::FooInterface>(),
|
||||
connection_client.get(), /* destroy_connection= */ false);
|
||||
connection_client.get(), /* destroy_connection= */ true);
|
||||
connection_client.release();
|
||||
foo_promise.set_value(std::move(foo_client));
|
||||
disconnect_client = [&] { loop.sync([&] { connection_client.reset(); }); };
|
||||
|
||||
auto connection_server = std::make_unique<mp::Connection>(loop, kj::mv(pipe.ends[1]), [&](mp::Connection& connection) {
|
||||
auto foo_server = kj::heap<mp::ProxyServer<gen::FooInterface>>(std::make_shared<FooImplementation>(), connection);
|
||||
@@ -106,8 +105,8 @@ void IpcPipeTest()
|
||||
auto script2{foo->passScript(script1)};
|
||||
BOOST_CHECK_EQUAL(HexStr(script1), HexStr(script2));
|
||||
|
||||
// Test cleanup: disconnect pipe and join thread
|
||||
disconnect_client();
|
||||
// Test cleanup: disconnect and join thread
|
||||
foo.reset();
|
||||
thread.join();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user