Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

golang accept on already opened fd

Tags:

go

I have a daemon that listens on a specific unix domain socket file. At some point it spawns a child which should continue listen on the same socket file without open a new one and overwriting the old one. I need a method that listen on a specific FD. In C it can be done with accept():

int accept(int sockfd, struct sockaddr *addr, socklen_t *addrlen);

Please advise.

like image 632
Zhivko Angelov Avatar asked Oct 30 '22 05:10

Zhivko Angelov


1 Answers

net.FileListener is used to turn a file descriptor into a net.Listener

f := os.NewFile(sockfd, "from parent")
l, err := net.FileListener(f)
if err != nil {
    log.Fatal(err)
}
like image 88
JimB Avatar answered Nov 15 '22 09:11

JimB