forked from bitcoin/bitcoin
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutil.h
More file actions
64 lines (54 loc) · 1.71 KB
/
Copy pathutil.h
File metadata and controls
64 lines (54 loc) · 1.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
// Copyright (c) The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#ifndef BITCOIN_IPC_UTIL_H
#define BITCOIN_IPC_UTIL_H
#include <tinyformat.h>
#include <util/strencodings.h>
#include <array>
#include <cstdint>
#include <functional>
#include <kj/debug.h>
#include <mp/proxy-io.h>
#include <mp/util.h>
#include <mp/version.h>
#include <sys/socket.h>
namespace mp {
// Definitions that can be deleted when libmultiprocess subtree is updated to
// v14. Having these allows Bitcoin Core changes to be decoupled from
// libmultiprocess changes so they don't have to be reviewed in a single PR.
#if MP_MAJOR_VERSION < 14
class EventLoop;
using ProcessId = int;
using SocketId = int;
inline constexpr SocketId SocketError{-1};
using Stream = SocketId;
inline Stream MakeStream(EventLoop&, SocketId socket)
{
return socket;
}
inline std::array<SocketId, 2> SocketPair()
{
int pair[2];
KJ_SYSCALL(socketpair(AF_UNIX, SOCK_STREAM, 0, pair));
return {pair[0], pair[1]};
}
inline std::tuple<ProcessId, SocketId> SpawnProcess(const std::function<std::vector<std::string>(std::string)>& spawn_argv)
{
ProcessId pid;
SocketId socket = SpawnProcess(pid, [&](int fd) { return spawn_argv(strprintf("%d", fd)); });
return {pid, socket};
}
inline SocketId StartSpawned(const std::string& connect_info)
{
auto socket = ToIntegral<SocketId>(connect_info);
if (!socket) throw std::invalid_argument(strprintf("Invalid socket descriptor '%s'", connect_info));
return *socket;
}
inline ThreadContext& CurrentThread()
{
return g_thread_context;
}
#endif
} // namespace mp
#endif // BITCOIN_IPC_UTIL_H