Chromium Code Reviews| Index: client/logdog/butlerlib/streamclient/client_npipe_posix.go |
| diff --git a/client/logdog/butlerlib/streamclient/client_npipe_posix.go b/client/logdog/butlerlib/streamclient/client_npipe_posix.go |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..404976cb71145fe04bb8284b40a5e68bcea8a63a |
| --- /dev/null |
| +++ b/client/logdog/butlerlib/streamclient/client_npipe_posix.go |
| @@ -0,0 +1,38 @@ |
| +// Copyright 2015 The Chromium 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 darwin dragonfly freebsd linux netbsd openbsd |
|
estaab
2015/11/06 22:09:44
What does this line do?
dnj (Google)
2015/11/07 16:47:41
This makes it so that Go build will only include t
|
| + |
| +package streamclient |
| + |
| +import ( |
| + "fmt" |
| + "io" |
| + "net" |
| + "os" |
| +) |
| + |
| +// Register POSIX-only protocols. |
| +func init() { |
| + registerProtocol("unix", newUnixSocketClient) |
| +} |
| + |
| +// newUnixSocketClient creates a new Client instance bound to a named pipe stream |
| +// server. |
| +// |
| +// newNPipeClient currently only works on POSIX (non-Windows) systems. |
| +func newUnixSocketClient(path string) (Client, error) { |
| + // Ensure that the supplied path exists and is a named pipe. |
| + info, err := os.Lstat(path) |
| + if err != nil { |
| + return nil, fmt.Errorf("failed to stat file [%s]: %s", path, err) |
| + } |
| + if info.Mode()&os.ModeSocket == 0 { |
| + return nil, fmt.Errorf("not a named pipe: [%s]", path) |
| + } |
| + |
| + return &clientImpl{func() (io.WriteCloser, error) { |
| + return net.Dial("unix", path) |
| + }}, nil |
| +} |