mpv icon indicating copy to clipboard operation
mpv copied to clipboard

io: support `mp_make_wakeup_pipe()` on Windows

Open ruihe774 opened this issue 1 year ago • 1 comments

This PR makes mp_make_wakeup_pipe() work on Windows, as discussed in #14933.

Note: I do not aim to undeprecate the C API, but only to undeprecate the Lua API and make it cross-platform. I do not deny that there are workarounds to achieve the purpose (i.e. custom event loop), but IMO making the existing API cross-platform is simplest and most straighforward.

Sample Lua code for testing (work on both Windows and POSIX):

local uv = require('luv')
local fd = mp.get_wakeup_pipe()
local h = uv.new_pipe(false)
h:open(fd)
h:read_start(function(err)
    if err ~= nil then
        error(err)
    end

    print("waken up")

    mp.dispatch_events(false)
end)

function _G.mp_event_loop()
    while mp.keep_running do
        uv.run("once")
    end
end

ruihe774 avatar Sep 30 '24 10:09 ruihe774

Does this commit change anything with the behaviour of named pipes on Windows as before?

Hrxn avatar Dec 05 '24 16:12 Hrxn

Does this commit change anything with the behaviour of named pipes on Windows as before?

I did not get you. This PR uses named pipes to implement mp_make_wakeup_pipe(). mp_make_wakeup_pipe() is not supported on Windows before this PR, so it is certain that there are not existing usages of it on Windows, and this PR cannot cause any breaking changes. This PR is not related to other usages of named pipes besides in mp_make_wakeup_pipe().

ruihe774 avatar Dec 05 '24 19:12 ruihe774

Right, I'll better explain myself..

I was referring to this: https://mpv.io/manual/master/#command-prompt-example i.e. using the JSON IPC interface with named pipes on Windows.

But it does not seem that this commit is actually related, from a quick glance.

Edit:

Well, not actually this specific example with command prompt and echo.. the short paragraph below that one, actually.

Hrxn avatar Dec 05 '24 19:12 Hrxn

Right, I'll better explain myself..

I was referring to this: https://mpv.io/manual/master/#command-prompt-example i.e. using the JSON IPC interface with named pipes on Windows.

But it does not seem that this commit is actually related, from a quick glance.

Edit:

Well, not actually this specific example with command prompt and echo.. the short paragraph below that one, actually.

Yes, this PR has nothing to do with JSON IPC, which does not rely on mp_make_wakeup_pipe().

ruihe774 avatar Dec 05 '24 21:12 ruihe774