本文整理汇总了Golang中net.UnixListener.SetDeadline方法的典型用法代码示例。如果您正苦于以下问题:Golang UnixListener.SetDeadline方法的具体用法?Golang UnixListener.SetDeadline怎么用?Golang UnixListener.SetDeadline使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net.UnixListener
的用法示例。
在下文中一共展示了UnixListener.SetDeadline方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: accept
// listen for gui client to connect to our socket
func accept(listener *net.UnixListener, ch chan []byte) {
for {
// we are going to eat the serial data until
// we get a socket connection so we don't block the channel
select {
case <-ch:
log.Println("eating serial data")
default:
}
// set timeout to fall through so we can check the channel for
// serial data
listener.SetDeadline(time.Now().Add(100 * time.Millisecond))
conn, err := listener.AcceptUnix()
if nil != err {
if opErr, ok := err.(*net.OpError); ok && opErr.Timeout() {
continue
}
log.Println(err)
} else {
// we have connection, call handle, we only handle one connection
// so no goroutine here
handleSocket(conn, ch)
}
}
}
示例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)
}
}
}