-
Notifications
You must be signed in to change notification settings - Fork 48
Add nonunix platform support #274
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ryanofsky
wants to merge
20
commits into
bitcoin-core:master
Choose a base branch
from
ryanofsky:pr/wins
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 12 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
b15d63e
doc: Bump version 11 > 12
ryanofsky 36c91a0
util, refactor: Add ProcessId type alias and use it
ryanofsky 94af41b
util, refactor: Add SocketId type alias and use it
ryanofsky beaa50a
util, refactor: Add ConnectInfo type alias and use it
ryanofsky b16f8c4
util, refactor: Handle forking inside ExecProcess
ryanofsky 022b29b
util, refactor: Add SocketPair() and use it in SpawnProcess
ryanofsky 24c5e57
util: Clear FD_CLOEXEC on child socket before exec
ryanofsky 3c81cf2
proxy, refactor: Replace EventLoop wakeup fd integers with KJ stream …
ryanofsky 17a1952
cmake: Bump minimum required Cap'n Proto version to 0.9
ryanofsky 091f5e1
proxy, refactor: Change ConnectStream and ServeStream to accept strea…
ryanofsky bfc2db7
proxy: Call shutdownWrite() in Connection destructor
ryanofsky 1060a95
util, refactor: Fix PtrOrValue constructor for move-only types on MSVC
ryanofsky 362d416
proxy, refactor: Fix C4305 truncation warning in Accessor on MSVC
ryanofsky 3fd227c
type-interface, refactor: Fix typename decltype() SFINAE in CustomBui…
ryanofsky 926ae35
ci: Check out bitcoin/bitcoin PR #35084 instead of master
ryanofsky 28e4c7f
proxy: Fix shutdownWrite() exception handling on macOS with dynamic l…
ryanofsky f6aa627
ipc: Wrap mpgen main() in try-catch to print errors
ryanofsky 7f513a4
doc: Remove trailing whitespace
ryanofsky c9aa806
cmake: Replace capnp_PREFIX path construction with cmake-provided sym…
ryanofsky 7cb83a5
cmake: Fix CapnProto tool paths broken by Ubuntu Noble packaging bug
ryanofsky File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| CI_DESC="CI job using old Cap'n Proto and cmake versions" | ||
| CI_DIR=build-olddeps | ||
| export CXXFLAGS="-Werror -Wall -Wextra -Wpedantic -Wno-unused-parameter -Wno-error=array-bounds" | ||
| NIX_ARGS=(--argstr capnprotoVersion "0.7.1" --argstr cmakeVersion "3.12.4") | ||
| NIX_ARGS=(--argstr capnprotoVersion "0.9.2" --argstr cmakeVersion "3.12.4") | ||
| BUILD_ARGS=(-k) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,12 +5,15 @@ | |
| #ifndef MP_UTIL_H | ||
| #define MP_UTIL_H | ||
|
|
||
| #include <array> | ||
| #include <capnp/schema.h> | ||
| #include <cassert> | ||
| #include <cstddef> | ||
| #include <cstring> | ||
| #include <exception> | ||
| #include <functional> | ||
| #include <kj/async-io.h> | ||
| #include <kj/memory.h> | ||
| #include <kj/string-tree.h> | ||
| #include <mutex> | ||
| #include <string> | ||
|
|
@@ -136,7 +139,10 @@ struct PtrOrValue { | |
| std::variant<T*, T> data; | ||
|
|
||
| template <typename... Args> | ||
| PtrOrValue(T* ptr, Args&&... args) : data(ptr ? ptr : std::variant<T*, T>{std::in_place_type<T>, std::forward<Args>(args)...}) {} | ||
| PtrOrValue(T* ptr, Args&&... args) : data(std::in_place_type<T*>, ptr) | ||
| { | ||
| if (!ptr) data.template emplace<T>(std::forward<Args>(args)...); | ||
| } | ||
|
|
||
| T& operator*() { return data.index() ? std::get<T>(data) : *std::get<T*>(data); } | ||
| T* operator->() { return &**this; } | ||
|
|
@@ -249,25 +255,43 @@ std::string ThreadName(const char* exe_name); | |
| //! errors in python unit tests. | ||
| std::string LogEscape(const kj::StringTree& string, size_t max_size); | ||
|
|
||
| using Stream = kj::Own<kj::AsyncIoStream>; | ||
|
|
||
| using ProcessId = int; | ||
| using SocketId = int; | ||
| constexpr SocketId SocketError{-1}; | ||
|
|
||
| //! Information about parent process passed to child process as a command-line | ||
| //! argument. On unix this is the child socket fd number formatted as a string. | ||
| using ConnectInfo = std::string; | ||
|
|
||
| //! Callback type used by SpawnProcess below. | ||
| using FdToArgsFn = std::function<std::vector<std::string>(int fd)>; | ||
| using ConnectInfoToArgsFn = std::function<std::vector<std::string>(const ConnectInfo&)>; | ||
|
|
||
| //! Spawn a new process that communicates with the current process over a socket | ||
| //! pair. Returns pid through an output argument, and file descriptor for the | ||
| //! local side of the socket. | ||
| //! The fd_to_args callback is invoked in the parent process before fork(). | ||
| //! It must not rely on child pid/state, and must return the command line | ||
| //! arguments that should be used to execute the process. Embed the remote file | ||
| //! descriptor number in whatever format the child process expects. | ||
| int SpawnProcess(int& pid, FdToArgsFn&& fd_to_args); | ||
|
|
||
| //! Call execvp with vector args. | ||
| //! Not safe to call in a post-fork child of a multi-threaded process. | ||
| //! Currently only used by mpgen at build time. | ||
| void ExecProcess(const std::vector<std::string>& args); | ||
| //! pair. Calls connect_info_to_args callback with a connection string that | ||
| //! needs to be passed to the child process, and executes the argv command line | ||
| //! it returns. Returns child process id and socket id. | ||
| std::tuple<ProcessId, SocketId> SpawnProcess(ConnectInfoToArgsFn&& connect_info_to_args); | ||
|
|
||
| //! Spawn a process and return its process id. Caller should call WaitProcess | ||
| //! on the returned id. | ||
| ProcessId SpawnProcess(const std::vector<std::string>& args); | ||
|
|
||
| //! Initialize spawned child process using the ConnectInfo string passed to it, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. StartSpawned reads as imperative, but the body just parses an int out of the connect-info string (and the header comment seems to describe more work than the function actually does). Would something like ParseConnectInfo fit better? I might be missing the full picture here. |
||
| //! returning a socket id for communicating with the parent process. | ||
| SocketId StartSpawned(const ConnectInfo& connect_info); | ||
|
|
||
| //! Create a socket pair that can be used to communicate within a process or | ||
| //! between parent and child processes. | ||
| std::array<SocketId, 2> SocketPair(); | ||
|
|
||
| //! Start a process and return its process id. Caller should call WaitProcess | ||
| //! on the returned id. | ||
| ProcessId ExecProcess(const std::vector<std::string>& args); | ||
|
|
||
| //! Wait for a process to exit and return its exit code. | ||
| int WaitProcess(int pid); | ||
| int WaitProcess(ProcessId pid); | ||
|
|
||
| inline char* CharCast(char* c) { return c; } | ||
| inline char* CharCast(unsigned char* c) { return (char*)c; } | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this declaration proposital? It has no definition anywhere