diff --git a/doc.go b/doc.go index 66860382..81d7e6a7 100644 --- a/doc.go +++ b/doc.go @@ -491,6 +491,10 @@ Getting the file selection is similarly done with 'load' command: # do something else with $list fi +There is a 'quit' command to close client connections and quit the server: + + lf -remote 'quit' + Lastly, there is a 'conn' command to connect the server as a client. This should not be needed for users. diff --git a/docstring.go b/docstring.go index 44889a86..7fc20f3f 100644 --- a/docstring.go +++ b/docstring.go @@ -512,6 +512,10 @@ Getting the file selection is similarly done with 'load' command: # do something else with $list fi +There is a 'quit' command to close client connections and quit the server: + + lf -remote 'quit' + Lastly, there is a 'conn' command to connect the server as a client. This should not be needed for users. diff --git a/lf.1 b/lf.1 index 9148d595..0c707f46 100644 --- a/lf.1 +++ b/lf.1 @@ -501,6 +501,12 @@ Getting the file selection is similarly done with 'load' command: fi .EE .PP +There is a 'quit' command to close client connections and quit the server: +.PP +.EX + lf -remote 'quit' +.EE +.PP Lastly, there is a 'conn' command to connect the server as a client. This should not be needed for users. .SH FILE OPERATIONS lf uses the underlying 'cp' and 'mv' shell commands for file operations. For this purpose, when you 'copy' a file, it doesn't actually copy the file on the disk, but only records its name to memory. The actual file operation takes place when you 'paste' in which case the 'cp' command is used. Similarly the 'mv' command is used for 'cut' followed by 'paste'. diff --git a/server.go b/server.go index 1b1ad6aa..e18664c5 100644 --- a/server.go +++ b/server.go @@ -13,6 +13,8 @@ var ( gCopyFile bool gFileList []string gConnList = make(map[int]net.Conn) + gQuitChan = make(chan bool, 1) + gListener net.Listener ) func serve() { @@ -32,6 +34,8 @@ func serve() { } defer l.Close() + gListener = l + listen(l) } @@ -39,7 +43,13 @@ func listen(l net.Listener) { for { c, err := l.Accept() if err != nil { - log.Printf("accepting connection: %s", err) + select { + case <-gQuitChan: + log.Printf("bye!") + return + default: + log.Printf("accepting connection: %s", err) + } } go handleConn(c) } @@ -103,6 +113,14 @@ func handleConn(c net.Conn) { } } } + case "quit": + gQuitChan <- true + for _, c := range gConnList { + fmt.Fprintln(c, "echo server is quitting...") + c.Close() + } + gListener.Close() + break default: log.Printf("listen: unexpected command: %s", word) }