Skip to content

Commit

Permalink
optimize io
Browse files Browse the repository at this point in the history
  • Loading branch information
lxzan committed Jan 13, 2023
1 parent d982242 commit fcb4ee7
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
10 changes: 5 additions & 5 deletions writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down

0 comments on commit fcb4ee7

Please sign in to comment.