diff options
author | Ryan Ofsky <ryan@ofsky.org> | 2024-07-17 10:37:52 -0400 |
---|---|---|
committer | Ryan Ofsky <ryan@ofsky.org> | 2024-09-06 09:08:10 -0400 |
commit | 73fe7d723084653671f2178ea1177a8627edfafa (patch) | |
tree | 9c0c834918c2fd4679e1c8a674167a5ffd1d0104 /src/ipc | |
parent | 955d4077aac621697246bcb20a854ba97e37c519 (diff) | |
download | bitcoin-73fe7d723084653671f2178ea1177a8627edfafa.tar.xz |
multiprocess: Add unit tests for connect, serve, and listen functions
Diffstat (limited to 'src/ipc')
-rw-r--r-- | src/ipc/capnp/protocol.cpp | 3 | ||||
-rw-r--r-- | src/ipc/protocol.h | 8 |
2 files changed, 9 insertions, 2 deletions
diff --git a/src/ipc/capnp/protocol.cpp b/src/ipc/capnp/protocol.cpp index 9d18d62102..4b67a5bd1e 100644 --- a/src/ipc/capnp/protocol.cpp +++ b/src/ipc/capnp/protocol.cpp @@ -61,11 +61,12 @@ public: } mp::ListenConnections<messages::Init>(*m_loop, listen_fd, init); } - void serve(int fd, const char* exe_name, interfaces::Init& init) override + void serve(int fd, const char* exe_name, interfaces::Init& init, const std::function<void()>& ready_fn = {}) override { assert(!m_loop); mp::g_thread_context.thread_name = mp::ThreadName(exe_name); m_loop.emplace(exe_name, &IpcLogFn, &m_context); + if (ready_fn) ready_fn(); mp::ServeStream<messages::Init>(*m_loop, fd, init); m_loop->loop(); m_loop.reset(); diff --git a/src/ipc/protocol.h b/src/ipc/protocol.h index 1e355784ad..b2ebf99e8c 100644 --- a/src/ipc/protocol.h +++ b/src/ipc/protocol.h @@ -50,7 +50,13 @@ public: //! created by them. This isn't really a problem because serve() is only //! called by spawned child processes that call it immediately to //! communicate back with parent processes. - virtual void serve(int fd, const char* exe_name, interfaces::Init& init) = 0; + // + //! The optional `ready_fn` callback will be called after the event loop is + //! created but before it is started. This can be useful in tests to trigger + //! client connections from another thread as soon as the event loop is + //! available, but should not be neccessary in normal code which starts + //! clients and servers independently. + virtual void serve(int fd, const char* exe_name, interfaces::Init& init, const std::function<void()>& ready_fn = {}) = 0; //! Add cleanup callback to interface that will run when the interface is //! deleted. |