1 // Copyright (c) 2021-present The Bitcoin Core developers
2 // Distributed under the MIT software license, see the accompanying
3 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
4 5 #ifndef BITCOIN_IPC_PROCESS_H
6 #define BITCOIN_IPC_PROCESS_H
7 8 #include <util/fs.h>
9 10 #include <memory>
11 #include <string>
12 13 namespace ipc {
14 class Protocol;
15 16 //! IPC process interface for spawning bitcoin processes and serving requests
17 //! in processes that have been spawned.
18 //!
19 //! There will be different implementations of this interface depending on the
20 //! platform (e.g. unix, windows).
21 class Process
22 {
23 public:
24 virtual ~Process() = default;
25 26 //! Spawn process and return socket file descriptor for communicating with
27 //! it.
28 virtual int spawn(const std::string& new_exe_name, const fs::path& argv0_path, int& pid) = 0;
29 30 //! Wait for spawned process to exit and return its exit code.
31 virtual int waitSpawned(int pid) = 0;
32 33 //! Parse command line and determine if current process is a spawned child
34 //! process. If so, return true and a file descriptor for communicating
35 //! with the parent process.
36 virtual bool checkSpawned(int argc, char* argv[], int& fd) = 0;
37 38 //! Canonicalize and connect to address, returning socket descriptor.
39 virtual int connect(const fs::path& data_dir,
40 const std::string& dest_exe_name,
41 std::string& address) = 0;
42 43 //! Create listening socket, bind and canonicalize address, and return socket descriptor.
44 virtual int bind(const fs::path& data_dir,
45 const std::string& exe_name,
46 std::string& address) = 0;
47 };
48 49 //! Constructor for Process interface. Implementation will vary depending on
50 //! the platform (unix or windows).
51 std::unique_ptr<Process> MakeProcess();
52 } // namespace ipc
53 54 #endif // BITCOIN_IPC_PROCESS_H
55