OLD | NEW |
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 streamclient | 5 package streamclient |
6 | 6 |
7 import ( | 7 import ( |
8 "io" | 8 "io" |
9 "net" | 9 "net" |
10 | 10 |
11 "github.com/luci/luci-go/common/errors" | 11 "github.com/luci/luci-go/common/errors" |
12 ) | 12 ) |
13 | 13 |
14 func tcpProtocolClientFactory(netType string) ClientFactory { | 14 func tcpProtocolClientFactory(netType string) ClientFactory { |
15 return func(spec string) (Client, error) { | 15 return func(spec string) (Client, error) { |
16 raddr, err := net.ResolveTCPAddr(netType, spec) | 16 raddr, err := net.ResolveTCPAddr(netType, spec) |
17 if err != nil { | 17 if err != nil { |
18 » » » return nil, errors.Annotate(err).Reason("could not resol
ve %(net)q address from %(spec)q"). | 18 » » » return nil, errors.Annotate(err, "could not resolve %q a
ddress from %q", netType, spec).Err() |
19 » » » » D("net", netType). | |
20 » » » » D("spec", spec). | |
21 » » » » Err() | |
22 } | 19 } |
23 | 20 |
24 if raddr.IP == nil || raddr.IP.IsUnspecified() { | 21 if raddr.IP == nil || raddr.IP.IsUnspecified() { |
25 » » » return nil, errors.Reason("a valid %(net)q address must
be provided"). | 22 » » » return nil, errors.Reason("a valid %q address must be pr
ovided", netType).Err() |
26 » » » » D("net", netType). | |
27 » » » » Err() | |
28 } | 23 } |
29 | 24 |
30 if raddr.Port <= 0 { | 25 if raddr.Port <= 0 { |
31 return nil, errors.New("a valid port must be provided") | 26 return nil, errors.New("a valid port must be provided") |
32 } | 27 } |
33 | 28 |
34 return &clientImpl{ | 29 return &clientImpl{ |
35 factory: func() (io.WriteCloser, error) { | 30 factory: func() (io.WriteCloser, error) { |
36 conn, err := net.DialTCP(netType, nil, raddr) | 31 conn, err := net.DialTCP(netType, nil, raddr) |
37 if err != nil { | 32 if err != nil { |
38 » » » » » return nil, errors.Annotate(err).Reason(
"failed to dial %(net)q address %(raddr)q"). | 33 » » » » » return nil, errors.Annotate(err, "failed
to dial %q address %q", netType, raddr).Err() |
39 » » » » » » D("net", netType). | |
40 » » » » » » D("raddr", raddr). | |
41 » » » » » » Err() | |
42 } | 34 } |
43 return conn, nil | 35 return conn, nil |
44 }, | 36 }, |
45 }, nil | 37 }, nil |
46 } | 38 } |
47 } | 39 } |
OLD | NEW |