RFC: adding fd-passing to win32

Thiago Macieira thiago at kde.org
Tue Aug 9 15:14:38 UTC 2022


On Tuesday, 9 August 2022 00:51:38 PDT Marc-André Lureau wrote:
> If we are able to find solutions at D-Bus level, it's not impossible they
> implement better low-level solutions in afunix.sys. See also cygwin
> discussion pointed by Lawrence.

You may want to think about widest compatibility too. I don't expect that 
afunix.sys will be as widespread, so implementing something that is able to 
work without it makes sense.

Compatibility with cygwin applications may not be your goal.

> My point is that 'h' is the right type to transfer FDs, not HANDLEs/SOCKET
> etc.

And you're still missing my point.

The backend implementation is irrelevant. The fact that you get a file 
descriptor in the API is the important bit, and if on Windows you transfer a 
HANDLE but the API needs to do _open_osfhandle to return something to the 
user, so be it.

Unless you tell us that you *can't* do that for SOCKETs, even if just as a 
holder so one can do _get_osfhandle later and get the HANDLE back.

> > If you use 'H', you'll first need to start with a spec update and you'll
> > need
> > to convince people like Simon and myself, who don't have as extensive
> > Windows
> > knowledge, that it is needed (and this thread is pointing that we aren't
> > getting convinced). You'll need code reviews throughout the implementation
> > to
> 
> Spec update will be needed for nego phase, details of HANDLE transfer etc.
> Reference implementation changes are required anyway.

Indeed, but those would be minor and focused. Not affecting the type system.

> Frankly, adding 'H' is minor compared to the rest of the changes involved.

No, it isn't.

> Regarding compatibility, the 'H' type won't be used unless capability is
> negotiated.

But it'll exist.

> SOCKET s = WSASocket(..)
> int fd = _open_osfhandle(s,..)
> dbus_message_append_args(.., DBUS_TYPE_UNIX_FD, &fd,..)
> 
> In libdbus, or receiver
> dbus_message_get_args(.., DBUS_TYPE_UNIX_FD, &fd)
> HANDLE h = _get_osfhandle(fd)
> if (is_socket(h)) /* see
> https://gitlab.gnome.org/GNOME/glib/-/blob/main/glib/gwin32.c#L1457 for ex
> */
> {
>   SOCKET s = (SOCKET)h;
>   ..
>   WSADuplicateSocket(s, ) to target process for ex..
>   ..
>   closesocket(s) /* in theory better than _close(), but this also unclear!
> */
> } else {
>   DuplicateHandle(h, )..
>   _close(fd)
> }
> 
> If we expose HANDLE & SOCKETs directly instead (both in APIs and protocol),
> we don't need to juggle with the fd back/forth mapping and potential
> guesses & pitfalls.

Thank you for more details.

But this tells me that the API would need to split between HANDLE and SOCKET, 
so wouldn't you need two types instead?

-- 
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
   Software Architect - Intel DCAI Cloud Engineering





More information about the dbus mailing list