From: Matt Joiner Date: Mon, 26 Jul 2021 00:18:24 +0000 (+1000) Subject: Trim UDP tracker client read allocations X-Git-Tag: v1.29.2 X-Git-Url: http://www.git.stargrave.org/?a=commitdiff_plain;h=83749028ece92ba3ec98769548f202ba372ac9e9;p=btrtrc.git Trim UDP tracker client read allocations --- diff --git a/tracker/udp/conn-client.go b/tracker/udp/conn-client.go index d7e19027..d789cc3b 100644 --- a/tracker/udp/conn-client.go +++ b/tracker/udp/conn-client.go @@ -23,8 +23,8 @@ type ConnClient struct { } func (cc *ConnClient) reader() { + b := make([]byte, 0x800) for { - b := make([]byte, 0x800) n, err := cc.conn.Read(b) if err != nil { // TODO: Do bad things to the dispatcher, and incoming calls to the client if we have a diff --git a/tracker/udp/dispatcher.go b/tracker/udp/dispatcher.go index 907eb15b..3aad927e 100644 --- a/tracker/udp/dispatcher.go +++ b/tracker/udp/dispatcher.go @@ -11,6 +11,7 @@ type Dispatcher struct { transactions map[TransactionId]Transaction } +// The caller owns b. func (me *Dispatcher) Dispatch(b []byte) error { buf := bytes.NewBuffer(b) var rh ResponseHeader @@ -23,7 +24,7 @@ func (me *Dispatcher) Dispatch(b []byte) error { if t, ok := me.transactions[rh.TransactionId]; ok { t.h(DispatchedResponse{ Header: rh, - Body: buf.Bytes(), + Body: append([]byte(nil), buf.Bytes()...), }) return nil } else {