blob: 362e512ce36add433bb55b61b3c4721d1b3efa4e [file] [log] [blame]
// +build fuchsia
package fdio
import (
"syscall/zx"
"syscall/zx/fidl"
"syscall/zx/io"
)
func ServiceConnect(svcpath string, h zx.Handle) error {
// Otherwise attempt to connect through the root namespace.
ns, err := NewNSFromMap(zx.RootNSMap)
if err == nil {
return ns.Connect(svcpath, h)
}
h.Close()
return zx.Error{Status: zx.ErrNotFound, Text: "fdio.ServiceConnect"}
}
func ServiceConnectAt(dir zx.Handle, path string, h zx.Handle) error {
if !dir.IsValid() || !h.IsValid() {
return zx.Error{Status: zx.ErrInvalidArgs, Text: "fdio.ServiceConnectAt"}
}
// Open the path on the remote.
iface := (*io.DirectoryInterface)(&fidl.ChannelProxy{Channel: zx.Channel(dir)})
req := io.NodeInterfaceRequest(fidl.InterfaceRequest{Channel: zx.Channel(h)})
err := iface.Open(io.OpenRightReadable|io.OpenRightWritable, 0755, path, req)
if err != nil {
h.Close()
return err
}
return nil
}