5#ifndef MP_PROXY_TYPE_CONTEXT_H
6#define MP_PROXY_TYPE_CONTEXT_H
14template <
typename Output>
19 typename std::enable_if<std::is_same<
decltype(output.get()), Context::Builder>::value>::type*
enable =
nullptr)
30 GuardedRef{thread_context.waiter->m_mutex, thread_context.callback_threads}, &connection,
31 [&] {
return connection.m_threads.add(kj::heap<
ProxyServer<Thread>>(connection, thread_context, std::thread{})); })};
43 auto request = connection.m_thread_map.makeThreadRequest();
44 request.setName(thread_context.thread_name);
45 return request.send().getResult();
48 GuardedRef{thread_context.waiter->m_mutex, thread_context.request_threads},
51 auto context = output.init();
58template <
typename Accessor,
typename ServerContext,
typename Fn,
typename... Args>
60 typename std::enable_if<
61 std::is_same<
decltype(Accessor::get(
server_context.call_context.getParams())), Context::Reader>::value,
62 kj::Promise<typename ServerContext::CallContext>>::type
73 auto self = server.thisCap();
106 server_context.request_canceled = true;
112 MP_LOG(loop,
Log::Info) <<
"IPC server request #" << req <<
" canceled while executing.";
133 [&] {
return Accessor::get(call_context.getParams()).getCallbackThread(); });
150 cancel_lock.m_lock.unlock();
174 ConnThreads::node_type removed;
176 Lock lock(thread_context.waiter->m_mutex);
183 MP_LOG(loop,
Log::Info) <<
"IPC server request #" << req <<
" canceled before it could be executed";
184 }
else KJ_IF_MAYBE(exception, kj::runCatchingExceptions([&]{
188 MP_LOG(loop,
Log::Info) <<
"IPC server request #" << req <<
" interrupted (" <<
e.what() <<
")";
191 MP_LOG(loop,
Log::Error) <<
"IPC server request #" << req <<
" uncaught exception (" << kj::str(*exception).cStr() <<
")";
192 kj::throwRecoverableException(kj::mv(*exception));
202 Context::Reader
context_arg = Accessor::get(params);
204 auto result = server.m_context.connection->m_threads.getLocalServer(
thread_client)
205 .then([&loop, invoke = kj::mv(invoke), req](
const kj::Maybe<Thread::Server&>&
perhaps)
mutable {
212 <<
"IPC server post request #" << req <<
" {" << thread.m_thread_context.thread_name <<
"}";
216 <<
"IPC server error request #" << req <<
", missing thread to execute request";
217 throw std::runtime_error(
"invalid thread handle");
225 return server.m_context.connection->m_canceler.wrap(kj::mv(result));
Helper class that detects when a promise is canceled.
Event loop implementation.
void sync(Callable &&callable)
Wrapper around EventLoop::post that takes advantage of the fact that callable will not go out of scop...
void * m_context
External context pointer.
std::function< void()> testing_hook_async_request_done
Hook called on the worker thread just before returning results.
std::function< void()> testing_hook_async_request_start
Hook called on the worker thread when it starts to execute an async request.
Functions to serialize / deserialize common bitcoin types.
ConnThreads::iterator ConnThread
auto PassField(Priority< 1 >, TypeList< LocalType & >, ServerContext &server_context, Fn &&fn, Args &&... args) -> Require< typename decltype(Accessor::get(server_context.call_context.getParams()))::Calls >
PassField override for callable interface reference arguments.
std::tuple< ConnThread, bool > SetThread(GuardedRef< ConnThreads > threads, Connection *connection, const std::function< Thread::Client()> &make_thread)
thread_local ThreadContext g_thread_context
ServerInvokeContext< ProxyServer< Interface >, ::capnp::CallContext< Params, Results > > ServerContext
void CustomBuildField(TypeList< LocalType >, Priority< 1 >, InvokeContext &invoke_context, Value &&value, Output &&output)
Overload multiprocess library's CustomBuildField hook to allow any serializable object to be stored i...
Exception thrown from code executing an IPC call that is interrupted.
Function parameter type for prioritizing overloaded function calls that would otherwise be ambiguous.
Mapping from capnp interface type to proxy server implementation (specializations are generated by pr...
Generic utility functions used by capnp code.
consteval auto _(util::TranslatedLiteral str)
constexpr auto Ticks(Dur2 d)
Helper to count the seconds of a duration/time_point.