本文整理匯總了Golang中net.UnixListener.Close方法的典型用法代碼示例。如果您正苦於以下問題:Golang UnixListener.Close方法的具體用法?Golang UnixListener.Close怎麽用?Golang UnixListener.Close使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類net.UnixListener
的用法示例。
在下文中一共展示了UnixListener.Close方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: Accept
func (us *UnixSock) Accept(l *net.UnixListener) {
// Why doesn't this get called on ctrl + c
defer l.Close()
for {
fd, err := l.Accept()
if err != nil {
break
}
us.processBuffer(fd)
}
}
示例2: listen
func listen(sock *net.UnixListener, logChan chan []byte) {
defer sock.Close()
defer wg.Done()
// Timeout after 2 seconds
sock.SetDeadline(time.Now().Add((2 * time.Second)))
for run {
client, err := sock.Accept()
if err != nil {
ne, ok := err.(net.Error)
if !ok || !ne.Temporary() {
// Non-temporary (fatal) error
log.Printf("Error accepting client:\n%v", err)
break
}
} else {
wg.Add(1)
go handle(client, logChan)
}
}
}
示例3: Run
// Run the server's accept loop, waiting for connections from l.
// Correct shutdown procedure is:
// set slots to a number such that no new processes will run
// wait for all running processes to finish
// set shittingDown to true
// close the listening socket
func Run(v *viper.Viper, l *net.UnixListener) {
i := newInstance(v)
i.listener = l
for {
c, err := l.AcceptUnix()
i.m.Lock()
sdc := i.shutdownComplete
i.m.Unlock()
if sdc {
glog.Infoln("Shutdown complete. closing listener.")
if c != nil {
c.Close()
}
l.Close()
return
} else if err != nil {
glog.Errorln("Accept() failed on unix socket:", err)
return
}
go i.connectionHandler(c)
}
}