[Libguestfs] [PATCH libnbd v2 3/3] golang: Add straightforward bindings, without callbacks.

Daniel P. Berrangé berrange at redhat.com
Wed Mar 18 09:37:18 UTC 2020


On Tue, Mar 17, 2020 at 09:20:13PM +0000, Richard W.M. Jones wrote:
> +  | Fd _ -> "int/*XXX*/"

snip.

> +  | RFd -> "int/*XXX*/"

snip.

> +  | RFd -> "0/*XXX*/"

snip.

> +  | RFd -> Some "-1/*XXX*/"

snip.

For passing file descriptors in or out of Go APIs you'll want to use
the os.File object.

To pass it from Go to C use a param 'file os.File' and call 'C.int(file.Fd())'
to get the POSIX file descriptor to pass to C. libvirt-go OpenGraphics API
gives an illustration of this.

For the reverse direction from C to Go use

   os.NewFile(uintptr(fd), "name")

where 'name' is any sensibiel identifying short name. libvirt-go
OpenGraphicsFD gives an illustration of this direction.

Regards,
Daniel
-- 
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|




More information about the Libguestfs mailing list