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() } }
// 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 }
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) } }
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 } } }
func resetTimeout(ws *websocket.Conn, timeout time.Duration) { if timeout > 0 { ws.SetDeadline(time.Now().Add(timeout)) } }