From e654700bd2f4785dab35900b6b55d4bf92183746 Mon Sep 17 00:00:00 2001 From: Gokcehan Date: Fri, 21 Jul 2017 01:26:36 +0300 Subject: [PATCH] use tcp sockets on windows Mentioned in #12. --- client.go | 8 ++++---- main.go | 10 +++++++++- server.go | 2 +- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/client.go b/client.go index af0a66b8..93f6e02e 100644 --- a/client.go +++ b/client.go @@ -33,7 +33,7 @@ func client() { var serverChan <-chan expr - c, err := net.Dial("unix", gSocketPath) + c, err := net.Dial(gSocketProt, gSocketPath) if err != nil { msg := fmt.Sprintf("connecting server: %s", err) app.ui.message = msg @@ -97,7 +97,7 @@ func readExpr(c net.Conn) <-chan expr { } func saveFiles(list []string, copy bool) error { - c, err := net.Dial("unix", gSocketPath) + c, err := net.Dial(gSocketProt, gSocketPath) if err != nil { return fmt.Errorf("dialing to save files: %s", err) } @@ -119,7 +119,7 @@ func saveFiles(list []string, copy bool) error { } func loadFiles() (list []string, copy bool, err error) { - c, e := net.Dial("unix", gSocketPath) + c, e := net.Dial(gSocketProt, gSocketPath) if e != nil { err = fmt.Errorf("dialing to load files: %s", e) return @@ -158,7 +158,7 @@ func loadFiles() (list []string, copy bool, err error) { } func sendRemote(cmd string) error { - c, err := net.Dial("unix", gSocketPath) + c, err := net.Dial(gSocketProt, gSocketPath) if err != nil { return fmt.Errorf("dialing to send server: %s", err) } diff --git a/main.go b/main.go index f4b5c673..cc9b0505 100644 --- a/main.go +++ b/main.go @@ -7,6 +7,7 @@ import ( "os" "os/exec" "path/filepath" + "runtime" "runtime/pprof" ) @@ -22,6 +23,7 @@ var ( gClientID int gLastDirPath string gSelectionPath string + gSocketProt string gSocketPath string gLogPath string gServerLogPath string @@ -48,7 +50,13 @@ func init() { tmp := os.TempDir() - gSocketPath = filepath.Join(tmp, fmt.Sprintf("lf.%s.sock", envUser)) + if runtime.GOOS == "windows" { + gSocketProt = "tcp" + gSocketPath = ":12345" + } else { + gSocketProt = "unix" + gSocketPath = filepath.Join(tmp, fmt.Sprintf("lf.%s.sock", envUser)) + } gClientID = 1000 gLogPath = filepath.Join(tmp, fmt.Sprintf("lf.%s.%d.log", envUser, gClientID)) diff --git a/server.go b/server.go index a3eeb994..62ddafe9 100644 --- a/server.go +++ b/server.go @@ -26,7 +26,7 @@ func serve() { log.Print("hi!") - l, err := net.Listen("unix", gSocketPath) + l, err := net.Listen(gSocketProt, gSocketPath) if err != nil { log.Printf("listening socket: %s", err) return