package main import ( "fmt" "github.com/dballard/warren/lib/warren" "log" "net" "os" "os/signal" "syscall" ) func cmdHandle(c net.Conn) { defer c.Close() fmt.Println("cmdHandle") data, err := warren.ReadStringz(c) if err != nil { fmt.Println(err) return } fmt.Println("cmdHandle got command:", string(data)) c.Write([]byte("echo: " + data)) } func main() { cmdSock, err := net.Listen(warren.CmdSockType(), warren.CmdSockAddr()) defer cmdSock.Close() if err != nil { log.Fatal("Listen on sock error:", err) } // Handle signals c := make(chan os.Signal, 1) signal.Notify(c, syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT, syscall.SIGHUP, ) go func() { _ = <-c cmdSock.Close() }() for { fd, err := cmdSock.Accept() fmt.Println("accept") if err != nil { log.Fatal("accpet error:", err) } go cmdHandle(fd) } }