| // Copyright 2018 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. | |
| // Go's distribution tools attempt to compile everything; this file | |
| // depends on types that don't compile in not-Fuchsia. | |
| //go:build fuchsia | |
| package fdio | |
| import ( | |
| "syscall/zx" | |
| "syscall/zx/fidl" | |
| "syscall/zx/internal/context" | |
| "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.DirectoryWithCtxInterface)(&fidl.ChannelProxy{Channel: zx.Channel(dir)}) | |
| req := io.NodeWithCtxInterfaceRequest(fidl.InterfaceRequest{Channel: zx.Channel(h)}) | |
| err := iface.Open(context.Background(), io.OpenFlagsRightReadable|io.OpenFlagsRightWritable, 0755, path, req) | |
| if err != nil { | |
| h.Close() | |
| return err | |
| } | |
| return nil | |
| } |