本文整理匯總了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)
}
}
}