| 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 package main | 5 package main |
| 6 | 6 |
| 7 import ( | 7 import ( |
| 8 "errors" | 8 "errors" |
| 9 "fmt" | 9 "fmt" |
| 10 "os" |
| 10 | 11 |
| 11 "github.com/luci/luci-go/client/internal/logdog/butler/streamserver" | 12 "github.com/luci/luci-go/client/internal/logdog/butler/streamserver" |
| 12 "golang.org/x/net/context" | 13 "golang.org/x/net/context" |
| 13 ) | 14 ) |
| 14 | 15 |
| 15 const ( | 16 const ( |
| 16 // An example stream server URI. | 17 // An example stream server URI. |
| 17 // | 18 // |
| 18 // This expands to: //localhost/pipe/<name> | 19 // This expands to: //localhost/pipe/<name> |
| 19 exampleStreamServerURI = streamServerURI("net.pipe:logdog-butler") | 20 exampleStreamServerURI = streamServerURI("net.pipe:logdog-butler") |
| 20 ) | 21 ) |
| 21 | 22 |
| 23 // interruptSignals is the set of signals to handle gracefully (e.g., flush, |
| 24 // shutdown). |
| 25 var interruptSignals = []os.Signal{ |
| 26 os.Interrupt, |
| 27 } |
| 28 |
| 22 type streamServerURI string | 29 type streamServerURI string |
| 23 | 30 |
| 24 func (u streamServerURI) Parse() (string, error) { | 31 func (u streamServerURI) Parse() (string, error) { |
| 25 typ, value := parseStreamServer(string(u)) | 32 typ, value := parseStreamServer(string(u)) |
| 26 if typ != "net.pipe" { | 33 if typ != "net.pipe" { |
| 27 return "", errors.New("Unsupported URI scheme.") | 34 return "", errors.New("Unsupported URI scheme.") |
| 28 } | 35 } |
| 29 | 36 |
| 30 if value == "" { | 37 if value == "" { |
| 31 return "", errors.New("cannot have empty pipe name") | 38 return "", errors.New("cannot have empty pipe name") |
| 32 } | 39 } |
| 33 return value, nil | 40 return value, nil |
| 34 } | 41 } |
| 35 | 42 |
| 36 // Validates that the URI is correct for Windows. | 43 // Validates that the URI is correct for Windows. |
| 37 func (u streamServerURI) Validate() error { | 44 func (u streamServerURI) Validate() error { |
| 38 _, err := u.Parse() | 45 _, err := u.Parse() |
| 39 return err | 46 return err |
| 40 } | 47 } |
| 41 | 48 |
| 42 // Create a Windows stream server. | 49 // Create a Windows stream server. |
| 43 func createStreamServer(ctx context.Context, uri streamServerURI) streamserver.S
treamServer { | 50 func createStreamServer(ctx context.Context, uri streamServerURI) streamserver.S
treamServer { |
| 44 name, err := uri.Parse() | 51 name, err := uri.Parse() |
| 45 if err != nil { | 52 if err != nil { |
| 46 panic("Failed to parse stream server URI.") | 53 panic("Failed to parse stream server URI.") |
| 47 } | 54 } |
| 48 return streamserver.NewNamedPipeServer(ctx, fmt.Sprintf(`\\.\pipe\%s`, n
ame)) | 55 return streamserver.NewNamedPipeServer(ctx, fmt.Sprintf(`\\.\pipe\%s`, n
ame)) |
| 49 } | 56 } |
| OLD | NEW |