feat!: remove TCP socket support for server connections (#2527)

Windows has supported Unix domain sockets for quite some time now, so falling back to TCP sockets can be removed. As a result, Unix domain sockets will be used on all platforms.
This commit is contained in:
valoq authored and GitHub committed 2026-04-16 11:37:30 +10:00
1 parent 66bc58b4bf
commit 867cd99f50
5 files changed
+13 -33

No files matched your search

+3 -3
View File
@@ -120,12 +120,12 @@ func readExpr() <-chan expr {
go func() { go func() {
duration := 100 * time.Millisecond duration := 100 * time.Millisecond
c, err := net.Dial(gSocketProt, gSocketPath) c, err := net.Dial("unix", gSocketPath)
for err != nil { for err != nil {
log.Printf("connecting server: %s", err) log.Printf("connecting server: %s", err)
time.Sleep(duration) time.Sleep(duration)
duration *= 2 duration *= 2
c, err = net.Dial(gSocketProt, gSocketPath) c, err = net.Dial("unix", gSocketPath)
} }
if _, err := fmt.Fprintf(c, "conn %d\n", gClientID); err != nil { if _, err := fmt.Fprintf(c, "conn %d\n", gClientID); err != nil {
@@ -169,7 +169,7 @@ func readExpr() <-chan expr {
} }
func remote(req string) (string, error) { func remote(req string) (string, error) {
c, err := net.Dial(gSocketProt, gSocketPath) c, err := net.Dial("unix", gSocketPath)
if err != nil { if err != nil {
return "", fmt.Errorf("connecting to server: %w", err) return "", fmt.Errorf("connecting to server: %w", err)
} }
+6 -14
View File
@@ -35,7 +35,6 @@ var (
gHostname string gHostname string
gLastDirPath string gLastDirPath string
gSelectionPath string gSelectionPath string
gSocketProt string
gSocketPath string gSocketPath string
gLogPath string gLogPath string
gSelect string gSelect string
@@ -178,19 +177,13 @@ func startServer() {
} }
func checkServer() { func checkServer() {
if gSocketProt == "unix" { if _, err := os.Stat(gSocketPath); os.IsNotExist(err) {
if _, err := os.Stat(gSocketPath); os.IsNotExist(err) { startServer()
startServer() } else if _, err := net.Dial("unix", gSocketPath); err != nil {
} else if _, err := net.Dial(gSocketProt, gSocketPath); err != nil { if err := os.Remove(gSocketPath); err != nil {
if err := os.Remove(gSocketPath); err != nil { log.Print(err)
log.Print(err)
}
startServer()
}
} else {
if _, err := net.Dial(gSocketProt, gSocketPath); err != nil {
startServer()
} }
startServer()
} }
} }
@@ -316,7 +309,6 @@ Options:
flag.Parse() flag.Parse()
gSocketProt = gDefaultSocketProt
gSocketPath = gDefaultSocketPath gSocketPath = gDefaultSocketPath
if gLogPath != "" { if gLogPath != "" {
-1
View File
@@ -28,7 +28,6 @@ var (
var ( var (
gDefaultShell = "sh" gDefaultShell = "sh"
gDefaultShellFlag = "-c" gDefaultShellFlag = "-c"
gDefaultSocketProt = "unix"
gDefaultSocketPath string gDefaultSocketPath string
gDefaultHiddenFiles = []string{".*"} gDefaultHiddenFiles = []string{".*"}
) )
+2 -11
View File
@@ -9,7 +9,6 @@ import (
"path/filepath" "path/filepath"
"slices" "slices"
"strings" "strings"
"syscall"
"golang.org/x/sys/windows" "golang.org/x/sys/windows"
) )
@@ -26,7 +25,6 @@ var envPathExts []string
var ( var (
gDefaultShell = "cmd" gDefaultShell = "cmd"
gDefaultShellFlag = "/c" gDefaultShellFlag = "/c"
gDefaultSocketProt = "unix"
gDefaultSocketPath string gDefaultSocketPath string
gDefaultHiddenFiles []string gDefaultHiddenFiles []string
) )
@@ -106,15 +104,8 @@ func init() {
gTagsPath = filepath.Join(data, "lf", "tags") gTagsPath = filepath.Join(data, "lf", "tags")
gHistoryPath = filepath.Join(data, "lf", "history") gHistoryPath = filepath.Join(data, "lf", "history")
socket, err := syscall.Socket(syscall.AF_UNIX, syscall.SOCK_STREAM, 0) runtime := os.TempDir()
if err != nil { gDefaultSocketPath = filepath.Join(runtime, fmt.Sprintf("lf.%s.sock", gUser.Username))
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)
}
s := cmp.Or(os.Getenv("PATHEXT"), ".COM;.EXE;.BAT;.CMD") s := cmp.Or(os.Getenv("PATHEXT"), ".COM;.EXE;.BAT;.CMD")
for ext := range strings.SplitSeq(s, ";") { for ext := range strings.SplitSeq(s, ";") {
+2 -4
View File
@@ -29,11 +29,9 @@ func serve() {
log.Print("*************** starting server ***************") log.Print("*************** starting server ***************")
if gSocketProt == "unix" { setUserUmask()
setUserUmask()
}
l, err := net.Listen(gSocketProt, gSocketPath) l, err := net.Listen("unix", gSocketPath)
if err != nil { if err != nil {
log.Printf("listening socket: %s", err) log.Printf("listening socket: %s", err)
return return