]> Sergey Matveev's repositories - btrtrc.git/commitdiff
Trim UDP tracker client read allocations v1.29.2
authorMatt Joiner <anacrolix@gmail.com>
Mon, 26 Jul 2021 00:18:24 +0000 (10:18 +1000)
committerMatt Joiner <anacrolix@gmail.com>
Mon, 26 Jul 2021 00:18:24 +0000 (10:18 +1000)
tracker/udp/conn-client.go
tracker/udp/dispatcher.go

index d7e19027a8a9aac8e3d4a4fb788ebf2139ff4872..d789cc3bde643934b93f041fd587abbf91564474 100644 (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
index 907eb15b1e60633a4d1f351f75baafba76fa8119..3aad927e3848bfb5cbe742cd1c294ea4b6e9790a 100644 (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 {