add a sync.Pool of byte buffers with maximum packet size as cap

ref #217
This commit is contained in:
Lucas Clemente
2016-07-26 15:36:28 +02:00
parent 90aa8cfa95
commit 950e59fa3d
6 changed files with 56 additions and 4 deletions

View File

@@ -86,7 +86,8 @@ func (s *Server) Serve(conn *net.UDPConn) error {
s.connMutex.Unlock()
for {
data := make([]byte, protocol.MaxPacketSize)
data := getPacketBuffer()
data = data[:protocol.MaxPacketSize]
n, remoteAddr, err := conn.ReadFromUDP(data)
if err != nil {
if strings.HasSuffix(err.Error(), "use of closed network connection") {