File tree Expand file tree Collapse file tree 6 files changed +18
-7
lines changed
Expand file tree Collapse file tree 6 files changed +18
-7
lines changed Original file line number Diff line number Diff line change @@ -177,7 +177,7 @@ func (p swappableBufferPool) Put(i *[]byte) {
177177}
178178
179179func init () {
180- internal .SetDefaultBufferPoolForTesting .(func (mem.BufferPool ))(swappableBufferPool {mem .DefaultBufferPool ()})
180+ internal .SetDefaultBufferPool .(func (mem.BufferPool ))(swappableBufferPool {mem .DefaultBufferPool ()})
181181}
182182
183183var (
Original file line number Diff line number Diff line change @@ -31,6 +31,18 @@ import (
3131 "google.golang.org/grpc/mem"
3232)
3333
34+ // SetDefaultBufferPool sets the default buffer pool used by all grpc clients
35+ // and servers that do not have a buffer pool configured via WithBufferPool or
36+ // BufferPool. It also changes the buffer pool used by the proto codec, which
37+ // can't be changed otherwise. The provided buffer pool must be non-nil. The
38+ // default value is mem.DefaultBufferPool.
39+ //
40+ // NOTE: this function must only be called during initialization time (i.e. in
41+ // an init() function), and is not thread-safe. The last caller wins.
42+ func SetDefaultBufferPool (bufferPool mem.BufferPool ) {
43+ internal .SetDefaultBufferPool .(func (mem.BufferPool ))(bufferPool )
44+ }
45+
3446// WithBufferPool returns a grpc.DialOption that configures the use of bufferPool
3547// for parsing incoming messages on a grpc.ClientConn, and for temporary buffers
3648// when marshaling outgoing messages. By default, mem.DefaultBufferPool is used,
Original file line number Diff line number Diff line change 2626 // option to configure a shared buffer pool for a grpc.Server.
2727 BufferPool any // func (grpc.SharedBufferPool) grpc.ServerOption
2828
29+ // SetDefaultBufferPool updates the default buffer pool.
30+ SetDefaultBufferPool any // func(mem.BufferPool)
31+
2932 // AcceptCompressors is implemented by the grpc package and returns
3033 // a call option that restricts the grpc-accept-encoding header for a call.
3134 AcceptCompressors any // func(...string) grpc.CallOption
Original file line number Diff line number Diff line change @@ -216,10 +216,6 @@ var (
216216 // original state. Only called in testing functions.
217217 SnapshotMetricRegistryForTesting func () func ()
218218
219- // SetDefaultBufferPoolForTesting updates the default buffer pool, for
220- // testing purposes.
221- SetDefaultBufferPoolForTesting any // func(mem.BufferPool)
222-
223219 // SetBufferPoolingThresholdForTesting updates the buffer pooling threshold, for
224220 // testing purposes.
225221 SetBufferPoolingThresholdForTesting any // func(int)
Original file line number Diff line number Diff line change @@ -51,7 +51,7 @@ var failTestsOnLeakedBuffers = false
5151func init () {
5252 defaultPool := mem .DefaultBufferPool ()
5353 globalPool .Store (& defaultPool )
54- ( internal .SetDefaultBufferPoolForTesting .(func (mem.BufferPool ) ))(& globalPool )
54+ internal .SetDefaultBufferPool .(func (mem.BufferPool ))(& globalPool )
5555}
5656
5757var globalPool swappableBufferPool
Original file line number Diff line number Diff line change @@ -53,7 +53,7 @@ var defaultBufferPool BufferPool
5353func init () {
5454 defaultBufferPool = NewTieredBufferPool (defaultBufferPoolSizes ... )
5555
56- internal .SetDefaultBufferPoolForTesting = func (pool BufferPool ) {
56+ internal .SetDefaultBufferPool = func (pool BufferPool ) {
5757 defaultBufferPool = pool
5858 }
5959
You can’t perform that action at this time.
0 commit comments