Bitcoin Core 31.99.0
P2P Digital Currency
Public Member Functions | Public Attributes | List of all members
mp::Connection Class Reference

Object holding network & rpc state associated with either an incoming server connection, or an outgoing client connection. More...

#include <proxy-io.h>

Collaboration diagram for mp::Connection:
[legend]

Public Member Functions

 Connection (EventLoop &loop, kj::Own< kj::AsyncIoStream > &&stream_)
 
 Connection (EventLoop &loop, kj::Own< kj::AsyncIoStream > &&stream_, const std::function<::capnp::Capability::Client(Connection &)> &make_client)
 
 ~Connection ()
 Run cleanup functions. More...
 
CleanupIt addSyncCleanup (std::function< void()> fn)
 Register synchronous cleanup function to run on event loop thread (with access to capnp thread local variables) when disconnect() is called. More...
 
void removeSyncCleanup (CleanupIt it)
 
template<typename F >
void onDisconnect (F &&f)
 Add disconnect handler. More...
 

Public Attributes

EventLoopRef m_loop
 
kj::Own< kj::AsyncIoStream > m_stream
 
LoggingErrorHandler m_error_handler {*m_loop}
 
kj::TaskSet m_on_disconnect {m_error_handler}
 TaskSet used to cancel the m_network.onDisconnect() handler for remote disconnections, if the connection is closed locally first by deleting this Connection object. More...
 
::capnp::TwoPartyVatNetwork m_network
 
std::optional<::capnp::RpcSystem<::capnp::rpc::twoparty::VatId > > m_rpc_system
 
ThreadMap::Client m_thread_map {nullptr}
 
::capnp::CapabilityServerSet< Thread > m_threads
 Collection of server-side IPC worker threads (ProxyServer<Thread> objects previously returned by ThreadMap.makeThread) used to service requests to clients. More...
 
kj::Canceler m_canceler
 Canceler for canceling promises that we want to discard when the connection is destroyed. More...
 
CleanupList m_sync_cleanup_fns
 Cleanup functions to run if connection is broken unexpectedly. More...
 

Detailed Description

Object holding network & rpc state associated with either an incoming server connection, or an outgoing client connection.

It must be created and destroyed on the event loop thread. In addition to Cap'n Proto state, it also holds lists of callbacks to run when the connection is closed.

Definition at line 406 of file proxy-io.h.

Constructor & Destructor Documentation

◆ Connection() [1/2]

mp::Connection::Connection ( EventLoop loop,
kj::Own< kj::AsyncIoStream > &&  stream_ 
)
inline

Definition at line 409 of file proxy-io.h.

◆ Connection() [2/2]

mp::Connection::Connection ( EventLoop loop,
kj::Own< kj::AsyncIoStream > &&  stream_,
const std::function<::capnp::Capability::Client(Connection &)> &  make_client 
)
inline

Definition at line 413 of file proxy-io.h.

◆ ~Connection()

mp::Connection::~Connection ( )

Run cleanup functions.

Must be called from the event loop thread. First calls synchronous cleanup functions while blocked (to free capnp Capability::Client handles owned by ProxyClient objects), then schedules asynchronous cleanup functions to run in a worker thread (to run destructors of m_impl instances owned by ProxyServer objects).

Definition at line 83 of file proxy.cpp.

Here is the call graph for this function:

Member Function Documentation

◆ addSyncCleanup()

CleanupIt mp::Connection::addSyncCleanup ( std::function< void()>  fn)

Register synchronous cleanup function to run on event loop thread (with access to capnp thread local variables) when disconnect() is called.

any new i/o.

Definition at line 153 of file proxy.cpp.

Here is the caller graph for this function:

◆ onDisconnect()

template<typename F >
void mp::Connection::onDisconnect ( F &&  f)
inline

Add disconnect handler.

Definition at line 435 of file proxy-io.h.

Here is the caller graph for this function:

◆ removeSyncCleanup()

void mp::Connection::removeSyncCleanup ( CleanupIt  it)

Definition at line 167 of file proxy.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ m_canceler

kj::Canceler mp::Connection::m_canceler

Canceler for canceling promises that we want to discard when the connection is destroyed.

This is used to interrupt method calls that are still executing at time of disconnection.

Definition at line 467 of file proxy-io.h.

◆ m_error_handler

LoggingErrorHandler mp::Connection::m_error_handler {*m_loop}

Definition at line 448 of file proxy-io.h.

◆ m_loop

EventLoopRef mp::Connection::m_loop

Definition at line 446 of file proxy-io.h.

◆ m_network

::capnp::TwoPartyVatNetwork mp::Connection::m_network

Definition at line 453 of file proxy-io.h.

◆ m_on_disconnect

kj::TaskSet mp::Connection::m_on_disconnect {m_error_handler}

TaskSet used to cancel the m_network.onDisconnect() handler for remote disconnections, if the connection is closed locally first by deleting this Connection object.

Definition at line 452 of file proxy-io.h.

◆ m_rpc_system

std::optional<::capnp::RpcSystem<::capnp::rpc::twoparty::VatId> > mp::Connection::m_rpc_system

Definition at line 454 of file proxy-io.h.

◆ m_stream

kj::Own<kj::AsyncIoStream> mp::Connection::m_stream

Definition at line 447 of file proxy-io.h.

◆ m_sync_cleanup_fns

CleanupList mp::Connection::m_sync_cleanup_fns

Cleanup functions to run if connection is broken unexpectedly.

List will be empty if all ProxyClient are destroyed cleanly before the connection is destroyed.

Definition at line 472 of file proxy-io.h.

◆ m_thread_map

ThreadMap::Client mp::Connection::m_thread_map {nullptr}

Definition at line 458 of file proxy-io.h.

◆ m_threads

::capnp::CapabilityServerSet<Thread> mp::Connection::m_threads

Collection of server-side IPC worker threads (ProxyServer<Thread> objects previously returned by ThreadMap.makeThread) used to service requests to clients.

Definition at line 462 of file proxy-io.h.


The documentation for this class was generated from the following files: