Chromium Code Reviews| Index: logdog/client/butler/streamserver/namedPipe_windows.go |
| diff --git a/logdog/client/butler/streamserver/namedPipe_windows.go b/logdog/client/butler/streamserver/namedPipe_windows.go |
| index e848d56cdb0ddc087513b483eaad61cce32d3c67..d1245541fe9b8a16c5f6d506780eb121c6b96dba 100644 |
| --- a/logdog/client/butler/streamserver/namedPipe_windows.go |
| +++ b/logdog/client/butler/streamserver/namedPipe_windows.go |
| @@ -7,19 +7,40 @@ package streamserver |
| import ( |
| "net" |
| + "github.com/luci/luci-go/common/errors" |
| log "github.com/luci/luci-go/common/logging" |
| + |
| "golang.org/x/net/context" |
| npipe "gopkg.in/natefinch/npipe.v2" |
| ) |
| +// localNamedPipePrefix is the prefix that can be applied to a named pipe in |
| +// order to bind it exclusively to the local system. |
| +const localNamedPipePrefix = `\\.\pipe\` |
| + |
| +// maxWindowsNamedPipeLength is the maximum length of a Windows named pipe. |
| +const maxWindowsNamedPipeLength = 256 |
| + |
| // NewNamedPipeServer instantiates a new Windows named pipe server instance. |
| -func NewNamedPipeServer(ctx context.Context, address string) StreamServer { |
| - ctx = log.SetField(ctx, "address", address) |
| +func NewNamedPipeServer(ctx context.Context, name string) (StreamServer, error) { |
| + switch l := len(name); { |
| + case l == 0: |
| + return nil, errors.New("cannot have empty name") |
| + case l > maxWindowsNamedPipeLength: |
| + return nil, errors.Reason("name exceeds maximum length %(max)d"). |
| + D("name", name). |
| + D("max", maxWindowsNamedPipeLength). |
| + Err() |
| + } |
| + |
| + name = localNamedPipePrefix + name |
|
nodir
2017/03/06 22:29:44
this may be more than maxWindowsNamedPipeLength?
dnj
2017/03/06 22:39:30
This is fine - the name length is about the pipe n
|
| + ctx = log.SetField(ctx, "name", name) |
| return &listenerStreamServer{ |
| Context: ctx, |
| + address: "net.pipe:" + name, |
| gen: func() (net.Listener, error) { |
| log.Debugf(ctx, "Creating Windows server socket Listener.") |
| - return npipe.Listen(address) |
| + return npipe.Listen(name) |
| }, |
| - } |
| + }, nil |
| } |