Inside Bitcoin
Opening the selected file…
Inside Bitcoin
Opening the selected file…
The code behind the network, with room to understand it.
Release published 2026-10-28 · Snapshot fetched 2026-11-01. Latest stable release at fetch time; development branches and Git history are excluded. Only the selected code window and visible folders load here.
1// Copyright (c) The Bitcoin Core developers2// Distributed under the MIT software license, see the accompanying3// file COPYING or http://www.opensource.org/licenses/mit-license.php.5#ifndef BITCOIN_IPC_UTIL_H6#define BITCOIN_IPC_UTIL_H8#include <tinyformat.h>9#include <util/strencodings.h>11#include <array>12#include <cstdint>13#include <functional>14#include <kj/debug.h>15#include <mp/proxy-io.h>16#include <mp/util.h>17#include <mp/version.h>18#include <sys/socket.h>20namespace mp {21// Definitions that can be deleted when libmultiprocess subtree is updated to22// v14. Having these allows Bitcoin Core changes to be decoupled from23// libmultiprocess changes so they don't have to be reviewed in a single PR.24#if MP_MAJOR_VERSION < 1425class EventLoop;26using ProcessId = int;27using SocketId = int;28inline constexpr SocketId SocketError{-1};30using Stream = SocketId;31inline Stream MakeStream(EventLoop&, SocketId socket)32{33return socket;34}36inline std::array<SocketId, 2> SocketPair()37{38int pair[2];39KJ_SYSCALL(socketpair(AF_UNIX, SOCK_STREAM, 0, pair));40return {pair[0], pair[1]};41}43inline std::tuple<ProcessId, SocketId> SpawnProcess(const std::function<std::vector<std::string>(std::string)>& spawn_argv)44{45ProcessId pid;46SocketId socket = SpawnProcess(pid, [&](int fd) { return spawn_argv(strprintf("%d", fd)); });47return {pid, socket};48}50inline SocketId StartSpawned(const std::string& connect_info)51{52auto socket = ToIntegral<SocketId>(connect_info);53if (!socket) throw std::invalid_argument(strprintf("Invalid socket descriptor '%s'", connect_info));54return *socket;55}57inline ThreadContext& CurrentThread()58{59return g_thread_context;60}61#endif62} // namespace mp64#endif // BITCOIN_IPC_UTIL_H
Independent explanations by MyBitcoinExplorer. Not affiliated with or endorsed by Bitcoin Core. Guides are educational and do not replace the source or its tests.
Bitcoin Core source © its contributors, distributed under the MIT license. Original notices and bundled third-party licenses are retained in the source tree.