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

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

Issue 2737603003: Butler stream servers can generate client address. (Closed)
Patch Set: better comment 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 "github.com/luci/luci-go/logdog/client/butlerlib/streamclient"
13
11 "golang.org/x/net/context" 14 "golang.org/x/net/context"
12 npipe "gopkg.in/natefinch/npipe.v2" 15 npipe "gopkg.in/natefinch/npipe.v2"
13 ) 16 )
14 17
18 // maxWindowsNamedPipeLength is the maximum length of a Windows named pipe.
19 const maxWindowsNamedPipeLength = 256
20
15 // NewNamedPipeServer instantiates a new Windows named pipe server instance. 21 // NewNamedPipeServer instantiates a new Windows named pipe server instance.
16 func NewNamedPipeServer(ctx context.Context, address string) StreamServer { 22 func NewNamedPipeServer(ctx context.Context, name string) (StreamServer, error) {
17 » ctx = log.SetField(ctx, "address", address) 23 » switch l := len(name); {
24 » case l == 0:
25 » » return nil, errors.New("cannot have empty name")
26 » case l > maxWindowsNamedPipeLength:
27 » » return nil, errors.Reason("name exceeds maximum length %(max)d") .
28 » » » D("name", name).
29 » » » D("max", maxWindowsNamedPipeLength).
30 » » » Err()
31 » }
32
33 » ctx = log.SetField(ctx, "name", name)
18 return &listenerStreamServer{ 34 return &listenerStreamServer{
19 Context: ctx, 35 Context: ctx,
20 » » gen: func() (net.Listener, error) { 36 » » gen: func() (net.Listener, string, error) {
21 » » » log.Debugf(ctx, "Creating Windows server socket Listener .") 37 » » » address := "net.pipe:" + name
22 » » » return npipe.Listen(address) 38 » » » pipePath := streamclient.LocalNamedPipePath(name)
39 » » » log.Fields{
40 » » » » "addr": address,
41 » » » » "pipePath": pipePath,
42 » » » }.Debugf(ctx, "Creating Windows server socket Listener." )
43
44 » » » l, err := npipe.Listen(pipePath)
45 » » » if err != nil {
46 » » » » return nil, "", errors.Annotate(err).Reason("fai led to listen on named pipe").Err()
47 » » » }
48 » » » return l, address, nil
23 }, 49 },
24 » } 50 » }, nil
25 } 51 }
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