warren/cmd/warrend/main.go

41 lines
628 B
Go
Raw Normal View History

2014-12-14 19:55:56 +00:00
package main
import (
"fmt"
"log"
"net"
)
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("unix", "/tmp/warrend.sock")
if err != nil {
log.Fatal("Listen on sock error:", err)
}
for {
fd, err := cmdSock.Accept()
fmt.Println("accept")
if err != nil {
log.Fatal("accpet error:", err)
}
go cmdHandle(fd)
}
}