Bitcoin Core 28.99.0
P2P Digital Currency
Public Member Functions | Protected Member Functions | List of all members
interfaces::Ipc Class Referenceabstract

Interface providing access to interprocess-communication (IPC) functionality. More...

#include <ipc.h>

Public Member Functions

virtual ~Ipc ()=default
 
virtual std::unique_ptr< InitspawnProcess (const char *exe_name)=0
 Spawn a child process returning pointer to its Init interface. More...
 
virtual bool startSpawnedProcess (int argc, char *argv[], int &exit_status)=0
 If this is a spawned process, block and handle requests from the parent process by forwarding them to this process's Init interface, then return true. More...
 
virtual std::unique_ptr< InitconnectAddress (std::string &address)=0
 Connect to a socket address and make a client interface proxy object using provided callback. More...
 
virtual void listenAddress (std::string &address)=0
 Connect to a socket address and make a client interface proxy object using provided callback. More...
 
template<typename Interface >
void addCleanup (Interface &iface, std::function< void()> cleanup)
 Add cleanup callback to remote interface that will run when the interface is deleted. More...
 
virtual ipc::Contextcontext ()=0
 IPC context struct accessor (see struct definition for more description). More...
 

Protected Member Functions

virtual void addCleanup (std::type_index type, void *iface, std::function< void()> cleanup)=0
 Internal implementation of public addCleanup method (above) as a type-erased virtual function, since template functions can't be virtual. More...
 

Detailed Description

Interface providing access to interprocess-communication (IPC) functionality.

The IPC implementation is responsible for establishing connections between a controlling process and a process being controlled. When a connection is established, the process being controlled returns an interfaces::Init pointer to the controlling process, which the controlling process can use to get access to other interfaces and functionality.

When spawning a new process, the steps are:

  1. The controlling process calls interfaces::Ipc::spawnProcess(), which calls ipc::Process::spawn(), which spawns a new process and returns a socketpair file descriptor for communicating with it. interfaces::Ipc::spawnProcess() then calls ipc::Protocol::connect() passing the socketpair descriptor, which returns a local proxy interfaces::Init implementation calling remote interfaces::Init methods.
  2. The spawned process calls interfaces::Ipc::startSpawnProcess(), which calls ipc::Process::checkSpawned() to read command line arguments and determine whether it is a spawned process and what socketpair file descriptor it should use. It then calls ipc::Protocol::serve() to handle incoming requests from the socketpair and invoke interfaces::Init interface methods, and exit when the socket is closed.
  3. The controlling process calls local proxy interfaces::Init object methods to make other proxy objects calling other remote interfaces. It can also destroy the initial interfaces::Init object to close the connection and shut down the spawned process.

When connecting to an existing process, the steps are similar to spawning a new process, except a socket is created instead of a socketpair, and destroying an Init interface doesn't end the process, since there can be multiple connections.

Definition at line 49 of file ipc.h.

Constructor & Destructor Documentation

◆ ~Ipc()

virtual interfaces::Ipc::~Ipc ( )
virtualdefault

Member Function Documentation

◆ addCleanup() [1/2]

template<typename Interface >
void interfaces::Ipc::addCleanup ( Interface &  iface,
std::function< void()>  cleanup 
)
inline

Add cleanup callback to remote interface that will run when the interface is deleted.

Definition at line 76 of file ipc.h.

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

◆ addCleanup() [2/2]

virtual void interfaces::Ipc::addCleanup ( std::type_index  type,
void *  iface,
std::function< void()>  cleanup 
)
protectedpure virtual

Internal implementation of public addCleanup method (above) as a type-erased virtual function, since template functions can't be virtual.

◆ connectAddress()

virtual std::unique_ptr< Init > interfaces::Ipc::connectAddress ( std::string &  address)
pure virtual

Connect to a socket address and make a client interface proxy object using provided callback.

connectAddress returns an interface pointer if the connection was established, returns null if address is empty ("") or disabled ("0") or if a connection was refused but not required ("auto"), and throws an exception if there was an unexpected error.

◆ context()

virtual ipc::Context & interfaces::Ipc::context ( )
pure virtual

IPC context struct accessor (see struct definition for more description).

◆ listenAddress()

virtual void interfaces::Ipc::listenAddress ( std::string &  address)
pure virtual

Connect to a socket address and make a client interface proxy object using provided callback.

Throws an exception if there was an error.

◆ spawnProcess()

virtual std::unique_ptr< Init > interfaces::Ipc::spawnProcess ( const char *  exe_name)
pure virtual

Spawn a child process returning pointer to its Init interface.

◆ startSpawnedProcess()

virtual bool interfaces::Ipc::startSpawnedProcess ( int  argc,
char *  argv[],
int &  exit_status 
)
pure virtual

If this is a spawned process, block and handle requests from the parent process by forwarding them to this process's Init interface, then return true.

If this is not a spawned child process, return false.


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