OLD | NEW |
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 // +build darwin dragonfly freebsd linux netbsd openbsd | 5 // +build darwin dragonfly freebsd linux netbsd openbsd |
6 | 6 |
7 package streamserver | 7 package streamserver |
8 | 8 |
9 import ( | 9 import ( |
10 "net" | 10 "net" |
(...skipping 14 matching lines...) Expand all Loading... |
25 // NewUNIXDomainSocketServer instantiates a new POSIX domain soecket server | 25 // NewUNIXDomainSocketServer instantiates a new POSIX domain soecket server |
26 // instance. | 26 // instance. |
27 // | 27 // |
28 // No resources are actually created until methods are called on the returned | 28 // No resources are actually created until methods are called on the returned |
29 // server. | 29 // server. |
30 func NewUNIXDomainSocketServer(ctx context.Context, path string) (StreamServer,
error) { | 30 func NewUNIXDomainSocketServer(ctx context.Context, path string) (StreamServer,
error) { |
31 switch l := len(path); { | 31 switch l := len(path); { |
32 case l == 0: | 32 case l == 0: |
33 return nil, errors.New("cannot have empty path") | 33 return nil, errors.New("cannot have empty path") |
34 case l > maxPOSIXNamedSocketLength: | 34 case l > maxPOSIXNamedSocketLength: |
35 » » return nil, errors.Reason("path exceeds maximum length %(max)d")
. | 35 » » return nil, errors.Reason("path exceeds maximum length %d", maxP
OSIXNamedSocketLength). |
36 » » » D("path", path). | 36 » » » InternalReason("path(%s)", path).Err() |
37 » » » D("max", maxPOSIXNamedSocketLength). | |
38 » » » Err() | |
39 } | 37 } |
40 | 38 |
41 abs, err := filepath.Abs(path) | 39 abs, err := filepath.Abs(path) |
42 if err != nil { | 40 if err != nil { |
43 » » return nil, errors.Annotate(err).Reason("could not get absolute
path of [%(path)s]"). | 41 » » return nil, errors.Annotate(err, "could not get absolute path of
[%s]", path).Err() |
44 » » » D("path", path). | |
45 » » » Err() | |
46 } | 42 } |
47 path = abs | 43 path = abs |
48 | 44 |
49 ctx = log.SetField(ctx, "namedPipePath", path) | 45 ctx = log.SetField(ctx, "namedPipePath", path) |
50 return &listenerStreamServer{ | 46 return &listenerStreamServer{ |
51 Context: ctx, | 47 Context: ctx, |
52 gen: func() (net.Listener, string, error) { | 48 gen: func() (net.Listener, string, error) { |
53 log.Infof(ctx, "Creating POSIX server socket Listener.") | 49 log.Infof(ctx, "Creating POSIX server socket Listener.") |
54 | 50 |
55 // Cleanup any previous named pipe. We don't bother chec
king for the file | 51 // Cleanup any previous named pipe. We don't bother chec
king for the file |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 log.ErrorKey: err, | 93 log.ErrorKey: err, |
98 }.Debugf(l, "Failed to remove named pipe file on Close()
.") | 94 }.Debugf(l, "Failed to remove named pipe file on Close()
.") |
99 } | 95 } |
100 }() | 96 }() |
101 | 97 |
102 if err := l.Listener.Close(); err != nil { | 98 if err := l.Listener.Close(); err != nil { |
103 return err | 99 return err |
104 } | 100 } |
105 return nil | 101 return nil |
106 } | 102 } |
OLD | NEW |