This is a really simpler question about the idiom, but it serves as a good example. (BTW 100% go newb)
Attempted to listen to a unix socket and process messages. Stolen code from different places, but I can not "throw" things correctly.
package main
import "fmt"
import "net"
func main(){
ln,err := net.Listen("unix", "/var/service/daemon2")
if err!= nil {
fmt.Println(err)
return
}
for {
c, err := ln.Accept()
if err != nil {
fmt.Println(err)
continue
}
go handleServerConnection(c)
}
}
func handleServerConnection(c net.UnixConn) {
buff := make([]byte, 1024)
oob := make([]byte, 1024)
_,_,_,_,err:=c.ReadMsgUnix(buff,oob);
if err != nil {
fmt.Println(err)
}
}
I need the 'c' inside handleServerConnection to be of type UNIXConn so that I can call ReadUNixMsg. But the generic listening code creates a generic Conn object. So this code does not compile.
I tried various types of converting / casting like UnixConn (c), but all to no avail.
pm100 source
share