This commit is contained in:
crusader 2017-08-25 17:00:13 +09:00
parent 205ceb6dc1
commit f6cf23940d

View File

@ -54,30 +54,27 @@ func (c *client) run() {
hasReadTimeout := c.o.ReadTimeout > 0
c.conn.SetReadLimit(c.o.MaxMessageSize)
go func() {
defer func() {
c.o.onDisconnected(c)
}()
for {
if hasReadTimeout {
c.conn.SetReadDeadline(time.Now().Add(c.o.ReadTimeout))
}
// messageType, data, err := c.conn.ReadMessage()
messageType, r, err := c.conn.NextReader()
if err != nil {
if websocket.IsUnexpectedCloseError(err, websocket.CloseGoingAway) {
//c.fireError(err)
}
break
} else {
c.onMessage(messageType, r)
}
defer func() {
c.o.onDisconnected(c)
}()
for {
if hasReadTimeout {
c.conn.SetReadDeadline(time.Now().Add(c.o.ReadTimeout))
}
}()
// messageType, data, err := c.conn.ReadMessage()
messageType, r, err := c.conn.NextReader()
if err != nil {
if websocket.IsUnexpectedCloseError(err, websocket.CloseGoingAway) {
//c.fireError(err)
}
break
} else {
c.onMessage(messageType, r)
}
}
}
func (c *client) onMessage(messageType int, r io.Reader) {