Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(26)

Unified Diff: client/logdog/butlerlib/streamclient/client_npipe_posix.go

Issue 1429993002: LogDog: Add Butler stream server package. (Closed) Base URL: https://github.com/luci/luci-go@logdog-review-butlerproto
Patch Set: Fixed datagram check, now with unit tests! Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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
+}

Powered by Google App Engine
This is Rietveld 408576698