Skip to content

Commit

Permalink
增加测试覆盖度
Browse files Browse the repository at this point in the history
  • Loading branch information
guonaihong committed Jul 26, 2023
1 parent b4025b5 commit 9578a7c
Show file tree
Hide file tree
Showing 11 changed files with 467 additions and 42 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
*swp
/cover.cov
autobahn-testsuite
autobahn-client-testsuite-darwin-arm64
autobahn-client-testsuite-linux-amd64
Expand Down
1 change: 0 additions & 1 deletion benchmark_mask_test.go → benchmark_rand_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (

func Benchmark_Rand_Uint32(t *testing.B) {
for i := 0; i < t.N; i++ {
// newMask(maskValue[:])
_ = rand.Uint32()
}
}
1 change: 1 addition & 0 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ type Config struct {
decompression bool // 开启解压缩功能
compression bool // 开启压缩功能
ignorePong bool // 忽略pong消息
disableBufioClearHack bool // 关闭bufio的clear hack优化
utf8Check func([]byte) bool // utf8检查
readTimeout time.Duration
windowsMultipleTimesPayloadSize float32 // 设置几倍的payload大小
Expand Down
64 changes: 32 additions & 32 deletions conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -364,38 +364,38 @@ func (c *Conn) WriteMessage(op Opcode, writeBuf []byte) (err error) {
return frame.WriteFrame(&c.fw, c.c, writeBuf, rsv1, c.client, op, maskValue)
}

// 这是一个不安全的方法, writeBuf的格式必须是 14个字节的空白长度+需要写的payload组成
func (c *Conn) WriteMessageUnsafe(op Opcode, writeBuf []byte) (err error) {
// if op == opcode.Text {
// if !c.utf8Check(writeBuf) {
// return ErrTextNotUTF8
// }
// }

// rsv1 := c.compression && (op == opcode.Text || op == opcode.Binary)
// if rsv1 {
// var out wrapBuffer
// w := compressNoContextTakeover(&out, defaultCompressionLevel)
// if _, err = io.Copy(w, bytes.NewReader(writeBuf)); err != nil {
// return
// }

// if err = w.Close(); err != nil {
// return
// }
// writeBuf = out.Bytes()
// }

// // f.Opcode = op
// // f.PayloadLen = int64(len(writeBuf))
// maskValue := uint32(0)
// if c.client {
// maskValue = rand.Uint32()
// }

// return frame.WriteFrame(&c.fw, c.c, writeBuf, rsv1, c.client, op, maskValue)
return
}
// TODO 这是一个不安全的方法, writeBuf的格式必须是 14个字节的空白长度+需要写的payload组成
// func (c *Conn) WriteMessageUnsafe(op Opcode, writeBuf []byte) (err error) {
// if op == opcode.Text {
// if !c.utf8Check(writeBuf) {
// return ErrTextNotUTF8
// }
// }

// rsv1 := c.compression && (op == opcode.Text || op == opcode.Binary)
// if rsv1 {
// var out wrapBuffer
// w := compressNoContextTakeover(&out, defaultCompressionLevel)
// if _, err = io.Copy(w, bytes.NewReader(writeBuf)); err != nil {
// return
// }

// if err = w.Close(); err != nil {
// return
// }
// writeBuf = out.Bytes()
// }

// // f.Opcode = op
// // f.PayloadLen = int64(len(writeBuf))
// maskValue := uint32(0)
// if c.client {
// maskValue = rand.Uint32()
// }

// return frame.WriteFrame(&c.fw, c.c, writeBuf, rsv1, c.client, op, maskValue)
// return
// }

func (c *Conn) SetDeadline(t time.Time) error {
return c.c.SetDeadline(t)
Expand Down
1 change: 0 additions & 1 deletion parser_ext.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

// TODO 等重写http1.1 解析器, 再把这代码重写下
package quickws

import (
Expand Down
Loading

0 comments on commit 9578a7c

Please sign in to comment.