Skip to content

Commit

Permalink
transport: remove ReleaseBuf, use pool directly
Browse files Browse the repository at this point in the history
  • Loading branch information
IrineSistiana committed Nov 6, 2023
1 parent 5db7455 commit b16a871
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 10 deletions.
4 changes: 2 additions & 2 deletions pkg/upstream/transport/conn_traditional.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,10 +179,10 @@ func (dc *TraditionalDnsConn) readLoop() {
select {
case resChan <- r: // resChan has buffer
default:
ReleaseResp(r)
pool.ReleaseBuf(r)
}
} else {
ReleaseResp(r)
pool.ReleaseBuf(r)
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion pkg/upstream/transport/reuse.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"time"

"github.com/IrineSistiana/mosdns/v5/pkg/dnsutils"
"github.com/IrineSistiana/mosdns/v5/pkg/pool"
"go.uber.org/zap"
)

Expand Down Expand Up @@ -262,7 +263,7 @@ func (c *reusableConn) readLoop() {
c.m.Unlock()

if respChan == nil {
ReleaseResp(resp)
pool.ReleaseBuf(resp)
c.closeWithErr(errUnexpectedResp)
return
}
Expand Down
6 changes: 0 additions & 6 deletions pkg/upstream/transport/transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ import (
"errors"
"io"
"time"

"github.com/IrineSistiana/mosdns/v5/pkg/pool"
)

var (
Expand All @@ -35,10 +33,6 @@ var (
ErrLazyConnCannotReserveQueryExchanger = errors.New("lazy connection failed to reserve query exchanger")
)

func ReleaseResp(b *[]byte) {
pool.ReleaseBuf(b)
}

const (
defaultIdleTimeout = time.Second * 10
defaultDialTimeout = time.Second * 5
Expand Down
3 changes: 2 additions & 1 deletion pkg/upstream/upstream.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import (
"time"

"github.com/IrineSistiana/mosdns/v5/mlog"
"github.com/IrineSistiana/mosdns/v5/pkg/pool"
"github.com/IrineSistiana/mosdns/v5/pkg/upstream/bootstrap"
"github.com/IrineSistiana/mosdns/v5/pkg/upstream/doh"
"github.com/IrineSistiana/mosdns/v5/pkg/upstream/transport"
Expand Down Expand Up @@ -567,7 +568,7 @@ func (u *udpWithFallback) ExchangeContext(ctx context.Context, q []byte) (*[]byt
return nil, err
}
if msgTruncated(*r) {
transport.ReleaseResp(r)
pool.ReleaseBuf(r)
return u.t.ExchangeContext(ctx, q)
}
return r, nil
Expand Down

0 comments on commit b16a871

Please sign in to comment.