| Index: logdog/client/butler/streamserver/namedPipe_posix.go
|
| diff --git a/logdog/client/butler/streamserver/namedPipe_posix.go b/logdog/client/butler/streamserver/namedPipe_posix.go
|
| index 5a951db927a5ab032665c7e1ad09d899518dbff5..1defbd21d10f5ad75223db842a159d3d1cca5e2c 100644
|
| --- a/logdog/client/butler/streamserver/namedPipe_posix.go
|
| +++ b/logdog/client/butler/streamserver/namedPipe_posix.go
|
| @@ -10,15 +10,37 @@ import (
|
| "net"
|
| "os"
|
|
|
| + "github.com/luci/luci-go/common/errors"
|
| log "github.com/luci/luci-go/common/logging"
|
| +
|
| "golang.org/x/net/context"
|
| )
|
|
|
| -// NewNamedPipeServer instantiates a new POSIX named pipe server instance.
|
| -func NewNamedPipeServer(ctx context.Context, path string) StreamServer {
|
| +// maxPOSIXNamedSocketLength is the maximum length of a UNIX domain socket.
|
| +//
|
| +// This is defined by the UNIX_PATH_MAX constant, and is usually this value.
|
| +const maxPOSIXNamedSocketLength = 104
|
| +
|
| +// NewUNIXDomainSocketServer instantiates a new POSIX domain soecket server
|
| +// instance.
|
| +//
|
| +// No resources are actually created until methods are called on the returned
|
| +// server.
|
| +func NewUNIXDomainSocketServer(ctx context.Context, path string) (StreamServer, error) {
|
| + switch l := len(path); {
|
| + case l == 0:
|
| + return nil, errors.New("cannot have empty path")
|
| + case l > maxPOSIXNamedSocketLength:
|
| + return nil, errors.Reason("path exceeds maximum length %(max)d").
|
| + D("path", path).
|
| + D("max", maxPOSIXNamedSocketLength).
|
| + Err()
|
| + }
|
| +
|
| ctx = log.SetField(ctx, "namedPipePath", path)
|
| return &listenerStreamServer{
|
| Context: ctx,
|
| + address: "unix:" + path,
|
| gen: func() (net.Listener, error) {
|
| log.Infof(ctx, "Creating POSIX server socket Listener.")
|
|
|
| @@ -43,11 +65,11 @@ func NewNamedPipeServer(ctx context.Context, path string) StreamServer {
|
| }
|
| return &ul, nil
|
| },
|
| - }
|
| + }, nil
|
| }
|
|
|
| -// Wrapper around the "unix"-type Listener that cleans up the named pipe on
|
| -// creation and 'Close()'
|
| +// selfCleaningUNIXListener is a wrapper around the "unix"-type Listener that
|
| +// cleans up the named pipe on creation and Close().
|
| //
|
| // The standard Go Listener will unlink the file when Closed. However, it
|
| // doesn't do it in a deferred, so this will clean up if a panic is encountered
|
|
|