diff --git a/reader.go b/reader.go index 8e81efb3..3e27ca96 100644 --- a/reader.go +++ b/reader.go @@ -125,7 +125,7 @@ func (c *Conn) readMessage() error { if c.continuationBuffer == nil { return internal.CloseProtocolError } - if err := copyN(c.continuationBuffer, buf, int64(buf.Len())); err != nil { + if err := writeN(c.continuationBuffer, buf.Bytes(), buf.Len()); err != nil { return err } if c.continuationBuffer.Len() > c.config.MaxContentLength { diff --git a/writer.go b/writer.go index c9ec0151..4f800b96 100644 --- a/writer.go +++ b/writer.go @@ -65,21 +65,21 @@ func (c *Conn) WriteBinary(payload []byte) { // WriteText write text frame func (c *Conn) WriteText(payload string) { - c.emitError(c.writeMessage(OpcodeText, internal.StringToBytes(payload))) + c.WriteMessage(OpcodeText, internal.StringToBytes(payload)) } // WriteMessage write text/binary message // text message must be utf8 encoding // 发送文本/二进制消息, 文本消息必须是utf8编码 func (c *Conn) WriteMessage(opcode Opcode, payload []byte) { + if atomic.LoadUint32(&c.closed) == 1 { + return + } c.emitError(c.writeMessage(opcode, payload)) } +// writeMessage 关闭状态置为1后还能写, 以便发送关闭帧 func (c *Conn) writeMessage(opcode Opcode, payload []byte) error { - if atomic.LoadUint32(&c.closed) == 1 { - return nil - } - c.wmu.Lock() defer c.wmu.Unlock()