sending close frame from client i think

master
Jordan Orelli 4 years ago
parent 9a7866e0f5
commit 455dbd8a0c

@ -86,7 +86,11 @@ func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
for { for {
t, r, err := conn.NextReader() t, r, err := conn.NextReader()
if err != nil { if err != nil {
s.Error("read error: %v", err) if websocket.IsCloseError(err, websocket.CloseNormalClosure) {
s.Info("received close frame from client")
} else {
s.Error("read error: %v", err)
}
return return
} }

@ -87,6 +87,10 @@ func (c *Client) readLoop(notifications chan<- Response) {
for { for {
_, r, err := c.conn.NextReader() _, r, err := c.conn.NextReader()
if err != nil { if err != nil {
if websocket.IsCloseError(err, websocket.CloseNormalClosure) {
c.Info("received close frame from server")
break
}
c.Error("unable to get a reader frame: %v", err) c.Error("unable to get a reader frame: %v", err)
break break
} }
@ -155,18 +159,16 @@ func (c *Client) writeLoop() {
case shouldClose := <-c.done: case shouldClose := <-c.done:
if shouldClose { if shouldClose {
c.Info("sending close frame")
msg := websocket.FormatCloseMessage(websocket.CloseNormalClosure, "") msg := websocket.FormatCloseMessage(websocket.CloseNormalClosure, "")
if err := c.conn.WriteMessage(websocket.CloseMessage, msg); err != nil { if err := c.conn.WriteMessage(websocket.CloseMessage, msg); err != nil {
c.Error("failed to write close message: %v", err) c.Error("failed to write close message: %v", err)
} else {
c.Info("sent close frame")
} }
c.Info("closing connection")
if err := c.conn.Close(); err != nil {
c.Error("failed to close connection: %v", err)
}
c.Info("connection closed")
c.conn = nil c.conn = nil
return
} }
return
} }
} }
} }

Loading…
Cancel
Save