Skip to content
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

Merged
merged 4 commits into from
Jul 29, 2024

Conversation

na-na-hi
Copy link
Contributor

This makes --input-ipc-client work on Windows.

The comment was added in e2ab6b7,
but posix_spawn usage was removed in 5309497
to ensure CLOEXEC correctness.
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.
Copy link

github-actions bot commented Jul 29, 2024

Download the artifacts for this pull request:

Windows
macOS

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]) {
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor

@kasper93 kasper93 Jul 29, 2024

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);
            }
        }
    }

Copy link
Contributor Author

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) {
Copy link
Contributor

@kasper93 kasper93 Jul 29, 2024

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?

Copy link
Contributor Author

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.

@na-na-hi na-na-hi force-pushed the ipc-client-win branch 2 times, most recently from 8449c25 to f3e09a1 Compare July 29, 2024 15:39
@kasper93 kasper93 merged commit 40f1a89 into mpv-player:master Jul 29, 2024
25 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants