Skip to content

Commit

Permalink
exception recovery
Browse files Browse the repository at this point in the history
  • Loading branch information
lxzan committed Oct 12, 2023
1 parent d39703e commit 6066232
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 8 deletions.
6 changes: 2 additions & 4 deletions benchmark_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ func BenchmarkConn_ReadMessage(b *testing.B) {
config: upgrader.option.getConfig(),
}
var buf, _, _ = conn1.genFrame(OpcodeText, githubData)
var closer = &bufferWrapper{}

var reader = bytes.NewBuffer(buf.Bytes())
var conn2 = &Conn{
Expand All @@ -80,12 +79,11 @@ func BenchmarkConn_ReadMessage(b *testing.B) {
for i := 0; i < b.N; i++ {
internal.BufferReset(reader, buf.Bytes())
conn2.br.Reset(reader)
_ = conn2.readMessage(closer)
_ = conn2.readMessage()
}
})

b.Run("compress enabled", func(b *testing.B) {
var closer = &bufferWrapper{}
var upgrader = NewUpgrader(handler, &ServerOption{CompressEnabled: true})
var config = upgrader.option.getConfig()
var conn1 = &Conn{
Expand All @@ -112,7 +110,7 @@ func BenchmarkConn_ReadMessage(b *testing.B) {
for i := 0; i < b.N; i++ {
internal.BufferReset(reader, buf.Bytes())
conn2.br.Reset(reader)
_ = conn2.readMessage(closer)
_ = conn2.readMessage()
}
})
}
Expand Down
3 changes: 1 addition & 2 deletions conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,8 @@ func (c *Conn) init() *Conn {
// If HTTP Server is reused, it is recommended to enable goroutine, as blocking will prevent the context from being GC.
func (c *Conn) ReadLoop() {
c.handler.OnOpen(c)
closer := &bufferWrapper{}
for {
if err := c.readMessage(closer); err != nil {
if err := c.readMessage(); err != nil {
c.emitError(err)
break
}
Expand Down
4 changes: 2 additions & 2 deletions reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func (c *Conn) readControl() error {
}
}

func (c *Conn) readMessage(closer *bufferWrapper) error {
func (c *Conn) readMessage() error {
if c.isClosed() {
return internal.CloseNormalClosure
}
Expand Down Expand Up @@ -95,7 +95,7 @@ func (c *Conn) readMessage(closer *bufferWrapper) error {
var fin = c.fh.GetFIN()
var buf, index = binaryPool.Get(contentLength)
var p = buf.Bytes()[:contentLength]
closer.Buffer, closer.index = buf, index
var closer = bufferWrapper{buf, index}
defer closer.Close()

if err := internal.ReadN(c.br, p); err != nil {
Expand Down

0 comments on commit 6066232

Please sign in to comment.