Skip to content

Commit d19bbe8

Browse files
committed
change max message size functions name
1 parent 504db8e commit d19bbe8

File tree

6 files changed

+28
-25
lines changed

6 files changed

+28
-25
lines changed

call.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ func sendRequest(ctx context.Context, dopts dialOptions, compressor Compressor,
127127
return Errorf(codes.Internal, "callInfo maxSendMessageSize field uninitialized(nil)")
128128
}
129129
if len(outBuf) > *c.maxSendMessageSize {
130-
return Errorf(codes.ResourceExhausted, "Sent message larger than max (%d vs. %d)", len(outBuf), *c.maxSendMessageSize)
130+
return Errorf(codes.ResourceExhausted, "grpc: trying to send message larger than max (%d vs. %d)", len(outBuf), *c.maxSendMessageSize)
131131
}
132132
err = t.Write(stream, outBuf, opts)
133133
if err == nil && outPayload != nil {

clientconn.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,9 @@ func WithInitialConnWindowSize(s int32) DialOption {
126126
}
127127
}
128128

129-
// WithMaxMsgSize returns a DialOption which sets the maximum message size the client can receive. Deprecated: use WithMaxReceiveMessageSize instead.
129+
// WithMaxMsgSize returns a DialOption which sets the maximum message size the client can receive. Deprecated: use WithDefaultCallOptions(MaxCallRecvMsgSize(s)) instead.
130130
func WithMaxMsgSize(s int) DialOption {
131-
return WithDefaultCallOptions(WithMaxReceiveMessageSize(s))
131+
return WithDefaultCallOptions(MaxCallRecvMsgSize(s))
132132
}
133133

134134
// WithDefaultCallOptions returns a DialOption which sets the default CallOptions for calls over the connection.

rpc_util.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -219,16 +219,16 @@ func FailFast(failFast bool) CallOption {
219219
})
220220
}
221221

222-
// WithMaxReceiveMessageSize returns a CallOption which sets the maximum message size the client can receive.
223-
func WithMaxReceiveMessageSize(s int) CallOption {
222+
// MaxCallRecvMsgSize returns a CallOption which sets the maximum message size the client can receive.
223+
func MaxCallRecvMsgSize(s int) CallOption {
224224
return beforeCall(func(o *callInfo) error {
225225
o.maxReceiveMessageSize = &s
226226
return nil
227227
})
228228
}
229229

230-
// WithMaxSendMessageSize returns a CallOption which sets the maximum message size the client can send.
231-
func WithMaxSendMessageSize(s int) CallOption {
230+
// MaxCallSendMsgSize returns a CallOption which sets the maximum message size the client can send.
231+
func MaxCallSendMsgSize(s int) CallOption {
232232
return beforeCall(func(o *callInfo) error {
233233
o.maxSendMessageSize = &s
234234
return nil
@@ -289,7 +289,7 @@ func (p *parser) recvMsg(maxReceiveMessageSize int) (pf payloadFormat, msg []byt
289289
return pf, nil, nil
290290
}
291291
if length > uint32(maxReceiveMessageSize) {
292-
return 0, nil, Errorf(codes.ResourceExhausted, "grpc: Received message larger than max (%d vs. %d)", length, maxReceiveMessageSize)
292+
return 0, nil, Errorf(codes.ResourceExhausted, "grpc: received message larger than max (%d vs. %d)", length, maxReceiveMessageSize)
293293
}
294294
// TODO(bradfitz,zhaoq): garbage. reuse buffer after proto decoding instead
295295
// of making it for each message:
@@ -393,7 +393,7 @@ func recv(p *parser, c Codec, s *transport.Stream, dc Decompressor, m interface{
393393
if len(d) > maxReceiveMessageSize {
394394
// TODO: Revisit the error code. Currently keep it consistent with java
395395
// implementation.
396-
return Errorf(codes.ResourceExhausted, "grpc: Received message larger than max (%d vs. %d)", len(d), maxReceiveMessageSize)
396+
return Errorf(codes.ResourceExhausted, "grpc: received message larger than max (%d vs. %d)", len(d), maxReceiveMessageSize)
397397
}
398398
if err := c.Unmarshal(d, m); err != nil {
399399
return Errorf(codes.Internal, "grpc: failed to unmarshal the received message %v", err)

server.go

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,10 @@ type options struct {
131131
initialConnWindowSize int32
132132
}
133133

134-
var defaultServerOptions = options{maxReceiveMessageSize: defaultServerMaxReceiveMessageSize, maxSendMessageSize: defaultServerMaxSendMessageSize}
134+
var defaultServerOptions = options{
135+
maxReceiveMessageSize: defaultServerMaxReceiveMessageSize,
136+
maxSendMessageSize: defaultServerMaxSendMessageSize,
137+
}
135138

136139
// A ServerOption sets options such as credentials, codec and keepalive parameters, etc.
137140
type ServerOption func(*options)
@@ -187,23 +190,23 @@ func RPCDecompressor(dc Decompressor) ServerOption {
187190
}
188191
}
189192

190-
// MaxMsgSize returns a ServerOption to set the max message size in bytes for inbound mesages.
191-
// If this is not set, gRPC uses the default limit. Deprecated: use MaxReceiveMessageSize instead.
193+
// MaxMsgSize returns a ServerOption to set the max message size in bytes the server can receive.
194+
// If this is not set, gRPC uses the default limit. Deprecated: use MaxRecvMsgSize instead.
192195
func MaxMsgSize(m int) ServerOption {
193-
return MaxReceiveMessageSize(m)
196+
return MaxRecvMsgSize(m)
194197
}
195198

196-
// MaxReceiveMessageSize returns a ServerOption to set the max message size in bytes for inbound mesages.
199+
// MaxRecvMsgSize returns a ServerOption to set the max message size in bytes the server can receive.
197200
// If this is not set, gRPC uses the default 4MB.
198-
func MaxReceiveMessageSize(m int) ServerOption {
201+
func MaxRecvMsgSize(m int) ServerOption {
199202
return func(o *options) {
200203
o.maxReceiveMessageSize = m
201204
}
202205
}
203206

204-
// MaxSendMessageSize returns a ServerOption to set the max message size in bytes for outbound mesages.
207+
// MaxSendMsgSize returns a ServerOption to set the max message size in bytes the server can send.
205208
// If this is not set, gRPC uses the default 4MB.
206-
func MaxSendMessageSize(m int) ServerOption {
209+
func MaxSendMsgSize(m int) ServerOption {
207210
return func(o *options) {
208211
o.maxSendMessageSize = m
209212
}
@@ -669,7 +672,7 @@ func (s *Server) sendResponse(t transport.ServerTransport, stream *transport.Str
669672
grpclog.Fatalf("grpc: Server failed to encode response %v", err)
670673
}
671674
if len(p) > s.opts.maxSendMessageSize {
672-
return status.Errorf(codes.ResourceExhausted, "Sent message larger than max (%d vs. %d)", len(p), s.opts.maxSendMessageSize)
675+
return status.Errorf(codes.ResourceExhausted, "grpc: trying to send message larger than max (%d vs. %d)", len(p), s.opts.maxSendMessageSize)
673676
}
674677
err = t.Write(stream, p, opts)
675678
if err == nil && outPayload != nil {
@@ -773,7 +776,7 @@ func (s *Server) processUnaryRPC(t transport.ServerTransport, stream *transport.
773776
if len(req) > s.opts.maxReceiveMessageSize {
774777
// TODO: Revisit the error code. Currently keep it consistent with
775778
// java implementation.
776-
return status.Errorf(codes.ResourceExhausted, "Received message larger than max (%d vs. %d)", len(req), s.opts.maxReceiveMessageSize)
779+
return status.Errorf(codes.ResourceExhausted, "grpc: received message larger than max (%d vs. %d)", len(req), s.opts.maxReceiveMessageSize)
777780
}
778781
if err := s.opts.codec.Unmarshal(req, v); err != nil {
779782
return status.Errorf(codes.Internal, "grpc: error unmarshalling request: %v", err)

stream.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@ func (cs *clientStream) SendMsg(m interface{}) (err error) {
371371
return Errorf(codes.Internal, "callInfo maxSendMessageSize field uninitialized(nil)")
372372
}
373373
if len(out) > *cs.c.maxSendMessageSize {
374-
return Errorf(codes.ResourceExhausted, "Sent message larger than max (%d vs. %d)", len(out), *cs.c.maxSendMessageSize)
374+
return Errorf(codes.ResourceExhausted, "trying to send message larger than max (%d vs. %d)", len(out), *cs.c.maxSendMessageSize)
375375
}
376376
err = cs.t.Write(cs.s, out, &transport.Options{Last: false})
377377
if err == nil && outPayload != nil {
@@ -613,7 +613,7 @@ func (ss *serverStream) SendMsg(m interface{}) (err error) {
613613
return err
614614
}
615615
if len(out) > ss.maxSendMessageSize {
616-
return Errorf(codes.ResourceExhausted, "Sent message larger than max (%d vs. %d)", len(out), ss.maxSendMessageSize)
616+
return Errorf(codes.ResourceExhausted, "trying to send message larger than max (%d vs. %d)", len(out), ss.maxSendMessageSize)
617617
}
618618
if err := ss.t.Write(ss.s, out, &transport.Options{Last: false}); err != nil {
619619
return toRPCErr(err)

test/end2end_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -504,10 +504,10 @@ func (te *test) startServer(ts testpb.TestServiceServer) {
504504
sopts = append(sopts, grpc.MaxMsgSize(*te.maxMsgSize))
505505
}
506506
if te.maxServerReceiveMsgSize != nil {
507-
sopts = append(sopts, grpc.MaxReceiveMessageSize(*te.maxServerReceiveMsgSize))
507+
sopts = append(sopts, grpc.MaxRecvMsgSize(*te.maxServerReceiveMsgSize))
508508
}
509509
if te.maxServerSendMsgSize != nil {
510-
sopts = append(sopts, grpc.MaxSendMessageSize(*te.maxServerSendMsgSize))
510+
sopts = append(sopts, grpc.MaxSendMsgSize(*te.maxServerSendMsgSize))
511511
}
512512
if te.tapHandle != nil {
513513
sopts = append(sopts, grpc.InTapHandle(te.tapHandle))
@@ -610,10 +610,10 @@ func (te *test) clientConn() *grpc.ClientConn {
610610
opts = append(opts, grpc.WithMaxMsgSize(*te.maxMsgSize))
611611
}
612612
if te.maxClientReceiveMsgSize != nil {
613-
opts = append(opts, grpc.WithDefaultCallOptions(grpc.WithMaxReceiveMessageSize(*te.maxClientReceiveMsgSize)))
613+
opts = append(opts, grpc.WithDefaultCallOptions(grpc.MaxCallRecvMsgSize(*te.maxClientReceiveMsgSize)))
614614
}
615615
if te.maxClientSendMsgSize != nil {
616-
opts = append(opts, grpc.WithDefaultCallOptions(grpc.WithMaxSendMessageSize(*te.maxClientSendMsgSize)))
616+
opts = append(opts, grpc.WithDefaultCallOptions(grpc.MaxCallSendMsgSize(*te.maxClientSendMsgSize)))
617617
}
618618
switch te.e.security {
619619
case "tls":

0 commit comments

Comments
 (0)