本文整理匯總了Golang中golang.org/x/net/websocket.Conn.SetDeadline方法的典型用法代碼示例。如果您正苦於以下問題:Golang Conn.SetDeadline方法的具體用法?Golang Conn.SetDeadline怎麽用?Golang Conn.SetDeadline使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類golang.org/x/net/websocket.Conn
的用法示例。
在下文中一共展示了Conn.SetDeadline方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: Accept
func (s *Server) Accept(ws *websocket.Conn) {
ws.PayloadType = websocket.BinaryFrame
if _, err := NewConnection(s, ws); err != nil {
ws.SetDeadline(time.Now().Add(2 * time.Millisecond))
ws.Close()
}
}
示例2: setConn
// Reuse an established websocket.Conn.
func (c *Conn) setConn(ws *websocket.Conn) error {
c.ws.Store(ws)
c.connected.Store(true)
if err := ws.SetDeadline(time.Now().Add(c.deadline)); err != nil {
return fmt.Errorf("conn: error while setting websocket connection deadline: %v", err)
}
return nil
}
示例3: setDeadlines
func setDeadlines(ws *websocket.Conn) {
if err := ws.SetDeadline(time.Now().Add(100 * time.Hour)); err != nil {
log.Fatal(err)
}
if err := ws.SetReadDeadline(time.Now().Add(100 * time.Hour)); err != nil {
log.Fatal(err)
}
if err := ws.SetWriteDeadline(time.Now().Add(100 * time.Hour)); err != nil {
log.Fatal(err)
}
}
示例4: handleConnection
func (prod *Websocket) handleConnection(conn *websocket.Conn) {
idx := atomic.AddUint32(&prod.clientIdx, 1) >> 31
prod.clients[idx].conns = append(prod.clients[idx].conns, conn)
prod.clients[idx].doneCount++
buffer := make([]byte, 8)
conn.SetDeadline(time.Time{})
// Keep alive until connection is closed
for {
if _, err := conn.Read(buffer); err != nil {
conn.Close()
break
}
}
}
示例5: resetTimeout
func resetTimeout(ws *websocket.Conn, timeout time.Duration) {
if timeout > 0 {
ws.SetDeadline(time.Now().Add(timeout))
}
}