use valid pipe name on Windows
This commit is contained in:
@@ -18,13 +18,13 @@ func init() {
|
|||||||
if home, err := os.UserHomeDir(); err == nil {
|
if home, err := os.UserHomeDir(); err == nil {
|
||||||
socketPath = path.Join(home, "Library", "Caches", "supersonic", "supersonic.sock")
|
socketPath = path.Join(home, "Library", "Caches", "supersonic", "supersonic.sock")
|
||||||
} else if user, err := user.Current(); err == nil {
|
} else if user, err := user.Current(); err == nil {
|
||||||
socketPath = fmt.Sprintf("/tmp/supersonic-%s.sock", user.Name)
|
socketPath = fmt.Sprintf("/tmp/supersonic-%s.sock", user.Uid)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if runtime := os.Getenv("XDG_RUNTIME_DIR"); runtime != "" {
|
if runtime := os.Getenv("XDG_RUNTIME_DIR"); runtime != "" {
|
||||||
socketPath = path.Join(runtime, "supersonic.sock")
|
socketPath = path.Join(runtime, "supersonic.sock")
|
||||||
} else if user, err := user.Current(); err == nil {
|
} else if user, err := user.Current(); err == nil {
|
||||||
socketPath = fmt.Sprintf("/tmp/supersonic-%s.sock", user.Name)
|
socketPath = fmt.Sprintf("/tmp/supersonic-%s.sock", user.Uid)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,18 +4,26 @@ package ipc
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"net"
|
"net"
|
||||||
"time"
|
"os/user"
|
||||||
|
"regexp"
|
||||||
|
|
||||||
"github.com/Microsoft/go-winio"
|
"github.com/Microsoft/go-winio"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var pipeName = `\\.\pipe\supersonic`
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
if user, err := user.Current(); err == nil {
|
||||||
|
pipeName += regexp.MustCompile(`[^a-zA-Z0-9]+`).ReplaceAllString(user.Name, "")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func Dial() (net.Conn, error) {
|
func Dial() (net.Conn, error) {
|
||||||
timeout := 300 * time.Millisecond
|
return winio.DialPipe(pipeName, nil)
|
||||||
return winio.DialPipe("supersonic", &timeout)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func Listen() (net.Listener, error) {
|
func Listen() (net.Listener, error) {
|
||||||
return winio.ListenPipe("supersonic", nil)
|
return winio.ListenPipe(pipeName, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
func DestroyConn() error {
|
func DestroyConn() error {
|
||||||
|
|||||||
Reference in New Issue
Block a user