Skip to content

Commit

Permalink
fix xray-core OptionalFeatures
Browse files Browse the repository at this point in the history
  • Loading branch information
wyx2685 committed Jan 10, 2025
1 parent 4b0f4d8 commit 0df2606
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions core/xray/app/dispatcher/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,14 @@ func (r *cachedReader) Cache(b *buf.Buffer) {
if !mb.IsEmpty() {
r.cache, _ = buf.MergeMulti(r.cache, mb)
}
b.Clear()
rawBytes := b.Extend(buf.Size)
cacheLen := r.cache.Len()
if cacheLen <= b.Cap() {
b.Clear()
} else {
b.Release()
*b = *buf.NewWithSize(cacheLen)
}
rawBytes := b.Extend(cacheLen)
n := r.cache.Copy(rawBytes)
b.Resize(0, int32(n))
r.Unlock()
Expand Down Expand Up @@ -105,7 +111,7 @@ func init() {
common.Must(common.RegisterConfig((*Config)(nil), func(ctx context.Context, config interface{}) (interface{}, error) {
d := new(DefaultDispatcher)
if err := core.RequireFeatures(ctx, func(om outbound.Manager, router routing.Router, pm policy.Manager, sm stats.Manager, dc dns.Client) error {
core.RequireFeatures(ctx, func(fdns dns.FakeDNSEngine) {
core.OptionalFeatures(ctx, func(fdns dns.FakeDNSEngine) {
d.fdns = fdns
})
return d.Init(config.(*Config), om, router, pm, sm, dc)
Expand Down

0 comments on commit 0df2606

Please sign in to comment.