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

Side by Side Diff: logdog/client/butler/streamserver/namedPipe_windows.go

Issue 2737603003: Butler stream servers can generate client address. (Closed)
Patch Set: better Created 3 years, 9 months 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 unified diff | Download patch
OLDNEW
1 // Copyright 2015 The LUCI Authors. All rights reserved. 1 // Copyright 2015 The LUCI Authors. All rights reserved.
2 // Use of this source code is governed under the Apache License, Version 2.0 2 // Use of this source code is governed under the Apache License, Version 2.0
3 // that can be found in the LICENSE file. 3 // that can be found in the LICENSE file.
4 4
5 package streamserver 5 package streamserver
6 6
7 import ( 7 import (
8 "net" 8 "net"
9 9
10 "github.com/luci/luci-go/common/errors"
10 log "github.com/luci/luci-go/common/logging" 11 log "github.com/luci/luci-go/common/logging"
12
11 "golang.org/x/net/context" 13 "golang.org/x/net/context"
12 npipe "gopkg.in/natefinch/npipe.v2" 14 npipe "gopkg.in/natefinch/npipe.v2"
13 ) 15 )
14 16
17 // localNamedPipePrefix is the prefix that can be applied to a named pipe in
18 // order to bind it exclusively to the local system.
19 const localNamedPipePrefix = `\\.\pipe\`
20
21 // maxWindowsNamedPipeLength is the maximum length of a Windows named pipe.
22 const maxWindowsNamedPipeLength = 256
23
15 // NewNamedPipeServer instantiates a new Windows named pipe server instance. 24 // NewNamedPipeServer instantiates a new Windows named pipe server instance.
16 func NewNamedPipeServer(ctx context.Context, address string) StreamServer { 25 func NewNamedPipeServer(ctx context.Context, name string) (StreamServer, error) {
17 » ctx = log.SetField(ctx, "address", address) 26 » switch l := len(name); {
27 » case l == 0:
28 » » return nil, errors.New("cannot have empty name")
29 » case l > maxWindowsNamedPipeLength:
30 » » return nil, errors.Reason("name exceeds maximum length %(max)d") .
31 » » » D("name", name).
32 » » » D("max", maxWindowsNamedPipeLength).
33 » » » Err()
34 » }
35
36 » 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
37 » ctx = log.SetField(ctx, "name", name)
18 return &listenerStreamServer{ 38 return &listenerStreamServer{
19 Context: ctx, 39 Context: ctx,
40 address: "net.pipe:" + name,
20 gen: func() (net.Listener, error) { 41 gen: func() (net.Listener, error) {
21 log.Debugf(ctx, "Creating Windows server socket Listener .") 42 log.Debugf(ctx, "Creating Windows server socket Listener .")
22 » » » return npipe.Listen(address) 43 » » » return npipe.Listen(name)
23 }, 44 },
24 » } 45 » }, nil
25 } 46 }
OLDNEW
« no previous file with comments | « logdog/client/butler/streamserver/namedPipe_posix_test.go ('k') | logdog/client/butler/streamserver/namedPipe_windows_test.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698