How to do message loop integration (backend_fd not implemented for Windows)
Hello,
I'm trying to find how integrate libuv with the message loop of a Windows GUI application.
I found an article explaining that backend_fd has to be polled by a worker thread and a message sent to the main GUI thread. Unfortunately backend_fd feature is not implemented in libuv for windows.
So the question is: how to do message loop integration when using libuv under Windows OS?
Best regards François Piette
There's no official support. You could look at what Electron does, it integrates libuv with its own event loop somehow (I have no idea how.)
If nothing else, you can always run libuv on a dedicated thread. The message loop thread can then wake up libuv by means of a uv_async_t.
The other way around you'd probably use something like CreateEvent()? My win32 knowledge is somewhat antiquated, there may be better ways.
@bnoordhuis That is exactly what I did. This is the article I cited. Unfortunately, this integration based on backend_fd if not implemented for Windows as I said.
Running libuv on a dedicated thread is not an acceptable solution. It would make the application much much more difficult to write, loosing all the benefits of libuv. All events will have to have a proxy so that the real code is executed by the GUI thread.
CreateEvent is a solution. I have excellent Windows API knowledges. Unfortunately my libuv knowledge is very basic (Working with libuv for only a few days). And the source code is not very well documented. I have looked at libuv source code for unix but I don't understand the details.
If someone help me by explaining unix code and pointing important things, I'm sure I can implement into libuv the same backend_fd feature for Windows. I guess libuv community will accept my contribution.
That is exactly what I did. This is the article I cited.
The article talks about Electron using uv_backend_fd() on UNIX-like systems. It must be doing something else on Windows due to the aforementioned function not being implemented on that platform.
It's possible they float some patches that expose libuv's internals to Electron, e.g., https://github.com/libuv/libuv/pull/1007 (present in master but not v1.x - perhaps it could be back-ported.)
It's possible they float some patches that expose libuv's internals to Electron
They do and @saghul even documented it :)
https://github.com/libuv/libuv/issues/965#issue-168827326
I have no idea on how to apply those patches. Maybe there is a chance that will be included in a future release?