package main import ( "fmt" "github.com/dballard/warren/lib/warren" "log" "net" "os" "os/signal" "syscall" ) func cmdHandle(c net.Conn) { fmt.Println("cmdHandle") buf := make([]byte, 1024) // Max size of buff based on? nr, err := c.Read(buf) defer c.Close() if err != nil { fmt.Println("cmdHandle read error:", err) return } data := buf[0:nr] fmt.Println("cmdHandle got command:", string(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) } }