Skip to content

Commit

Permalink
unix sockets on windows (#1637)
Browse files Browse the repository at this point in the history
* Added support for unix sockets on windows

* Keep the fallback port consistent with the one before

* Moved socket check at the bottom of the init function

* Creating the unix socket in temp dir
  • Loading branch information
Catalyn45 authored Apr 7, 2024
1 parent 47634f2 commit 21d256d
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions os_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"os/user"
"path/filepath"
"strings"
"syscall"

"golang.org/x/sys/windows"
)
Expand All @@ -24,8 +25,8 @@ var envPathExt = os.Getenv("PATHEXT")
var (
gDefaultShell = "cmd"
gDefaultShellFlag = "/c"
gDefaultSocketProt = "tcp"
gDefaultSocketPath = "127.0.0.1:12345"
gDefaultSocketProt = "unix"
gDefaultSocketPath string
)

var (
Expand Down Expand Up @@ -98,6 +99,16 @@ func init() {
gMarksPath = filepath.Join(data, "lf", "marks")
gTagsPath = filepath.Join(data, "lf", "tags")
gHistoryPath = filepath.Join(data, "lf", "history")

socket, err := syscall.Socket(syscall.AF_UNIX, syscall.SOCK_STREAM, 0)
if err != nil {
gDefaultSocketProt = "tcp"
gDefaultSocketPath = "127.0.0.1:12345"
} else {
runtime := os.TempDir()
gDefaultSocketPath = filepath.Join(runtime, fmt.Sprintf("lf.%s.sock", gUser.Username))
syscall.Close(socket)
}
}

func detachedCommand(name string, arg ...string) *exec.Cmd {
Expand Down

0 comments on commit 21d256d

Please sign in to comment.