blob: f7af0dc08eeb620756865ff831cea07716ef9913 [file] [log] [blame]
// Copyright 2016 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// +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.Proxy{Channel: zx.Channel(dir)})
req := io.ObjectInterfaceRequest(fidl.InterfaceRequest{Channel: zx.Channel(h)})
err := iface.Open(io.KOpenRightReadable|io.KOpenRightWritable, 0755, path, req)
if err != nil {
h.Close()
return err
}
return nil
}