Skip to content

Commit

Permalink
fix udp input bug
Browse files Browse the repository at this point in the history
  • Loading branch information
it1804 committed Dec 2, 2020
1 parent ecfe41d commit 8c97de3
Showing 1 changed file with 1 addition and 4 deletions.
5 changes: 1 addition & 4 deletions common/input/udp.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ type (
wg *sync.WaitGroup
serviceName string
conf *UdpServerConf
bufferPool sync.Pool
}
)

Expand All @@ -34,7 +33,6 @@ func NewUdpServer(serviceName string, conf *UdpServerConf) *UdpServer {
conf: conf,
wg: &sync.WaitGroup{},
serviceName: serviceName,
bufferPool: sync.Pool{New: func() interface{} { return make([]byte, conf.MaxPacketSize) }},
}
}

Expand Down Expand Up @@ -76,7 +74,7 @@ func (h *udpConnHandler) receivePacket(c net.PacketConn, wg *sync.WaitGroup, pac
defer wg.Done()
defer c.Close()
for h.stop == false {
msg := h.server.bufferPool.Get().([]byte)
msg := make([]byte, packetSize)
nbytes, addr, err := c.ReadFrom(msg)

if h.stop {
Expand All @@ -87,6 +85,5 @@ func (h *udpConnHandler) receivePacket(c net.PacketConn, wg *sync.WaitGroup, pac
}
src := addr.((*net.UDPAddr)).IP
h.phandler.Handle(msg[:nbytes], nbytes, src)
h.server.bufferPool.Put(msg)
}
}

0 comments on commit 8c97de3

Please # to comment.