Trim UDP tracker client read allocations

This commit is contained in:
Matt Joiner 2021-07-26 10:18:24 +10:00
parent 1d53c170b0
commit 83749028ec
2 changed files with 3 additions and 2 deletions

View File

@ -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

View File

@ -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 {