Skip to content

Commit

Permalink
remove unnecessary memory zeroing in PacketServer.Serve
Browse files Browse the repository at this point in the history
Fixes layeh#24
  • Loading branch information
Tim Cooper committed Jun 26, 2018
1 parent b404be3 commit 56df981
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions server-packet.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,8 @@ func (s *PacketServer) Serve(conn net.PacketConn) error {
}
}()

var buff [MaxPacketLength]byte
for {
var buff [MaxPacketLength]byte
n, remoteAddr, err := conn.ReadFrom(buff[:])
if err != nil {
s.mu.Lock()
Expand All @@ -125,8 +125,7 @@ func (s *PacketServer) Serve(conn net.PacketConn) error {
continue
}

buffCopy := make([]byte, n)
copy(buffCopy, buff[:n])
buffCopy := append([]byte(nil), buff[:n]...)

atomic.AddInt32(&s.activeCount, 1)
go func(buff []byte, remoteAddr net.Addr) {
Expand Down

0 comments on commit 56df981

Please sign in to comment.