-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
input/ipc-win: support fd:https:// for --input-ipc-client #14607
Conversation
Mention the alternative ipc method through fd inheritance. Also fix a grammar mistake.
This makes --input-ipc-client work on Windows. To use this feature, a parent process needs to create a connected named pipe, wrap the server handle in a CRT fd, and then spawn mpv as a child process with the fd as the --input-ipc-client parameter. The process can then communicate through the client handle. The named pipe must be created duplex with overlapped IO and inheritable handles.
Download the artifacts for this pull request: |
Also rejects the case of "fd:https://" without any number which was silently accepted as 0.
@@ -464,6 +464,25 @@ struct mp_ipc_ctx *mp_init_ipc(struct mp_client_api *client_api, | |||
.client_api = client_api, | |||
}; | |||
|
|||
if (opts->ipc_client && opts->ipc_client[0]) { |
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.
I know it is copied from ipc-unix, but maybe we could reduce complexity, with helpers like bstr_startswith and bstrtoll?
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.
How? The string needs to be wrapped and there is stilI no steps being saved with this.
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.
How? The string needs to be wrapped and there is stilI no steps being saved with this.
See the attached code. I want to encourage people to use bstr more. Maybe it is not less steps, but removes magic number 5 and imho makes code more readable abstracting some details.
bstr str = bstr0(opts->ipc_client);
if (bstr_eatstart0(&str, "fd:https://")) {
int fd = -1;
long long ll = bstrtoll(str, &str, 10);
if (!str.len && ll >= 0 && ll <= INT_MAX)
fd = ll;
if (fd < 0) {
MP_ERR(arg, "Invalid IPC client argument: '%s'\n", opts->ipc_client);
} else {
HANDLE h = (HANDLE)_get_osfhandle(fd);
if (h && h != INVALID_HANDLE_VALUE && (intptr_t)h != -2) {
ipc_start_client_json(arg, -1, h);
} else {
MP_ERR(arg, "Invalid IPC client fd: '%d'\n", fd);
}
}
}
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.
Done.
input/ipc-unix.c
Outdated
} | ||
int fd = -1; | ||
bstr str = bstr0(opts->ipc_client); | ||
if (bstr_eatstart0(&str, "fd:https://") && str.len) { |
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.
This str.len
check is necessary?
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.
Yes. See commit message. Otherwise an empty string is parsed as 0.
8449c25
to
f3e09a1
Compare
This makes
--input-ipc-client
work on Windows.