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/tcp.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 2017 The LUCI Authors. All rights reserved. 1 // Copyright 2017 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 "fmt" 8 "fmt"
9 "net" 9 "net"
10 10
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 // exported stream server parameters (externally) or by calling Address 50 // exported stream server parameters (externally) or by calling Address
51 // (internally). 51 // (internally).
52 func NewTCP6Server(ctx context.Context, spec string) (StreamServer, error) { 52 func NewTCP6Server(ctx context.Context, spec string) (StreamServer, error) {
53 return newTCPServerImpl(ctx, "tcp6", spec, net.IPv6loopback) 53 return newTCPServerImpl(ctx, "tcp6", spec, net.IPv6loopback)
54 } 54 }
55 55
56 // Listen implements StreamServer. 56 // Listen implements StreamServer.
57 func newTCPServerImpl(ctx context.Context, netType, spec string, loopback net.IP ) (StreamServer, error) { 57 func newTCPServerImpl(ctx context.Context, netType, spec string, loopback net.IP ) (StreamServer, error) {
58 tcpAddr, err := net.ResolveTCPAddr(netType, spec) 58 tcpAddr, err := net.ResolveTCPAddr(netType, spec)
59 if err != nil { 59 if err != nil {
60 » » return nil, errors.Annotate(err).Reason("could not resolve %(net )q address %(addr)q"). 60 » » return nil, errors.Annotate(err, "could not resolve %q address % q", netType, spec).Err()
61 » » » D("net", netType).
62 » » » D("addr", spec).
63 » » » Err()
64 } 61 }
65 62
66 if tcpAddr.IP == nil { 63 if tcpAddr.IP == nil {
67 tcpAddr.IP = loopback 64 tcpAddr.IP = loopback
68 } 65 }
69 66
70 return &listenerStreamServer{ 67 return &listenerStreamServer{
71 Context: ctx, 68 Context: ctx,
72 address: fmt.Sprintf("%s:%s", netType, tcpAddr.String()), 69 address: fmt.Sprintf("%s:%s", netType, tcpAddr.String()),
73 gen: func() (net.Listener, string, error) { 70 gen: func() (net.Listener, string, error) {
74 l, err := net.ListenTCP(netType, tcpAddr) 71 l, err := net.ListenTCP(netType, tcpAddr)
75 if err != nil { 72 if err != nil {
76 » » » » return nil, "", errors.Annotate(err).Reason("fai led to listen to %(net)q address %(addr)q"). 73 » » » » return nil, "", errors.Annotate(err, "failed to listen to %q address %q", netType, tcpAddr).Err()
77 » » » » » D("net", netType).
78 » » » » » D("addr", tcpAddr).
79 » » » » » Err()
80 } 74 }
81 75
82 addr := fmt.Sprintf("%s:%s", netType, l.Addr().String()) 76 addr := fmt.Sprintf("%s:%s", netType, l.Addr().String())
83 log.Fields{ 77 log.Fields{
84 "addr": addr, 78 "addr": addr,
85 }.Debugf(ctx, "Listening on %q stream server...", netTyp e) 79 }.Debugf(ctx, "Listening on %q stream server...", netTyp e)
86 return l, addr, nil 80 return l, addr, nil
87 }, 81 },
88 }, nil 82 }, nil
89 } 83 }
OLDNEW
« no previous file with comments | « logdog/client/butler/streamserver/namedPipe_windows.go ('k') | logdog/client/butlerlib/bootstrap/bootstrap.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698