Browse Source

release buffer

pull/1269/head
Darien Raymond 6 years ago
parent
commit
cb378a9dbf
No known key found for this signature in database
GPG Key ID: 7251FFA14BB18169
  1. 9
      transport/internet/udp/hub.go

9
transport/internet/udp/hub.go

@ -95,7 +95,7 @@ func (h *Hub) start() {
buffer := buf.New()
var noob int
var addr *net.UDPAddr
err := buffer.AppendSupplier(func(b []byte) (int, error) {
err := buffer.Reset(func(b []byte) (int, error) {
n, nb, _, a, e := ReadUDPMsg(h.conn, b, oobBytes)
noob = nb
addr = a
@ -108,6 +108,11 @@ func (h *Hub) start() {
break
}
if buffer.IsEmpty() {
buffer.Release()
continue
}
payload := &Payload{
Content: buffer,
Source: net.UDPDestination(net.IPAddress(addr.IP), net.Port(addr.Port)),
@ -124,6 +129,8 @@ func (h *Hub) start() {
select {
case c <- payload:
default:
buffer.Release()
payload.Content = nil
}
}

Loading…
Cancel
Save