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

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

Issue 2963503003: [errors] Greatly simplify common/errors package. (Closed)
Patch Set: fix nits Created 3 years, 5 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 "golang.org/x/net/context" 10 "golang.org/x/net/context"
11 11
12 "github.com/luci/luci-go/common/errors" 12 "github.com/luci/luci-go/common/errors"
13 log "github.com/luci/luci-go/common/logging" 13 log "github.com/luci/luci-go/common/logging"
14 "github.com/luci/luci-go/logdog/client/butlerlib/streamclient" 14 "github.com/luci/luci-go/logdog/client/butlerlib/streamclient"
15 15
16 "github.com/Microsoft/go-winio" 16 "github.com/Microsoft/go-winio"
17 ) 17 )
18 18
19 // maxWindowsNamedPipeLength is the maximum length of a Windows named pipe. 19 // maxWindowsNamedPipeLength is the maximum length of a Windows named pipe.
20 const maxWindowsNamedPipeLength = 256 20 const maxWindowsNamedPipeLength = 256
21 21
22 // NewNamedPipeServer instantiates a new Windows named pipe server instance. 22 // NewNamedPipeServer instantiates a new Windows named pipe server instance.
23 func NewNamedPipeServer(ctx context.Context, name string) (StreamServer, error) { 23 func NewNamedPipeServer(ctx context.Context, name string) (StreamServer, error) {
24 switch l := len(name); { 24 switch l := len(name); {
25 case l == 0: 25 case l == 0:
26 return nil, errors.New("cannot have empty name") 26 return nil, errors.New("cannot have empty name")
27 case l > maxWindowsNamedPipeLength: 27 case l > maxWindowsNamedPipeLength:
28 » » return nil, errors.Reason("name exceeds maximum length %(max)d") . 28 » » return nil, errors.Reason("name exceeds maximum length %d", maxW indowsNamedPipeLength).
29 » » » D("name", name). 29 » » » InternalReason("name(%s)", name).Err()
30 » » » D("max", maxWindowsNamedPipeLength).
31 » » » Err()
32 } 30 }
33 31
34 ctx = log.SetField(ctx, "name", name) 32 ctx = log.SetField(ctx, "name", name)
35 return &listenerStreamServer{ 33 return &listenerStreamServer{
36 Context: ctx, 34 Context: ctx,
37 gen: func() (net.Listener, string, error) { 35 gen: func() (net.Listener, string, error) {
38 address := "net.pipe:" + name 36 address := "net.pipe:" + name
39 pipePath := streamclient.LocalNamedPipePath(name) 37 pipePath := streamclient.LocalNamedPipePath(name)
40 log.Fields{ 38 log.Fields{
41 "addr": address, 39 "addr": address,
42 "pipePath": pipePath, 40 "pipePath": pipePath,
43 }.Debugf(ctx, "Creating Windows server socket Listener." ) 41 }.Debugf(ctx, "Creating Windows server socket Listener." )
44 42
45 l, err := winio.ListenPipe(pipePath, nil) 43 l, err := winio.ListenPipe(pipePath, nil)
46 if err != nil { 44 if err != nil {
47 » » » » return nil, "", errors.Annotate(err).Reason("fai led to listen on named pipe").Err() 45 » » » » return nil, "", errors.Annotate(err, "failed to listen on named pipe").Err()
48 } 46 }
49 return l, address, nil 47 return l, address, nil
50 }, 48 },
51 }, nil 49 }, nil
52 } 50 }
OLDNEW
« no previous file with comments | « logdog/client/butler/streamserver/namedPipe_posix.go ('k') | logdog/client/butler/streamserver/tcp.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698