Skip to content

Commit

Permalink
optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
oq-x committed Aug 13, 2024
1 parent 242b015 commit 2f9ab5b
Showing 1 changed file with 2 additions and 10 deletions.
12 changes: 2 additions & 10 deletions net/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,18 +100,10 @@ func (conn *Conn) WritePacket(pk packet.Packet) error {
}

if conn.listener.cfg.CompressionThreshold < 0 || !conn.compressionSet { // no compression
var buf = pkpool.Get().(*bytes.Buffer)
buf.Reset()
defer pkpool.Put(buf)

if err := io.WriteVarInt(buf, int32(packetBuf.Len())); err != nil {
return err
}
if _, err := packetBuf.WriteTo(buf); err != nil {
if err := io.WriteVarInt(conn, int32(packetBuf.Len())); err != nil {
return err
}

_, err := buf.WriteTo(conn)
_, err := packetBuf.WriteTo(conn)
return err
} else { // yes compression
if conn.listener.cfg.CompressionThreshold > int32(packetBuf.Len()) { // packet is too small to be compressed
Expand Down

0 comments on commit 2f9ab5b

Please sign in to comment.