change max message size functions name

This commit is contained in:
Yuxuan Li
2017-05-19 11:08:40 -07:00
parent 504db8e582
commit d19bbe846e
6 changed files with 28 additions and 25 deletions

View File

@ -127,7 +127,7 @@ func sendRequest(ctx context.Context, dopts dialOptions, compressor Compressor,
return Errorf(codes.Internal, "callInfo maxSendMessageSize field uninitialized(nil)") return Errorf(codes.Internal, "callInfo maxSendMessageSize field uninitialized(nil)")
} }
if len(outBuf) > *c.maxSendMessageSize { if len(outBuf) > *c.maxSendMessageSize {
return Errorf(codes.ResourceExhausted, "Sent message larger than max (%d vs. %d)", len(outBuf), *c.maxSendMessageSize) return Errorf(codes.ResourceExhausted, "grpc: trying to send message larger than max (%d vs. %d)", len(outBuf), *c.maxSendMessageSize)
} }
err = t.Write(stream, outBuf, opts) err = t.Write(stream, outBuf, opts)
if err == nil && outPayload != nil { if err == nil && outPayload != nil {

View File

@ -126,9 +126,9 @@ func WithInitialConnWindowSize(s int32) DialOption {
} }
} }
// WithMaxMsgSize returns a DialOption which sets the maximum message size the client can receive. Deprecated: use WithMaxReceiveMessageSize instead. // WithMaxMsgSize returns a DialOption which sets the maximum message size the client can receive. Deprecated: use WithDefaultCallOptions(MaxCallRecvMsgSize(s)) instead.
func WithMaxMsgSize(s int) DialOption { func WithMaxMsgSize(s int) DialOption {
return WithDefaultCallOptions(WithMaxReceiveMessageSize(s)) return WithDefaultCallOptions(MaxCallRecvMsgSize(s))
} }
// WithDefaultCallOptions returns a DialOption which sets the default CallOptions for calls over the connection. // WithDefaultCallOptions returns a DialOption which sets the default CallOptions for calls over the connection.

View File

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

View File

@ -131,7 +131,10 @@ type options struct {
initialConnWindowSize int32 initialConnWindowSize int32
} }
var defaultServerOptions = options{maxReceiveMessageSize: defaultServerMaxReceiveMessageSize, maxSendMessageSize: defaultServerMaxSendMessageSize} var defaultServerOptions = options{
maxReceiveMessageSize: defaultServerMaxReceiveMessageSize,
maxSendMessageSize: defaultServerMaxSendMessageSize,
}
// A ServerOption sets options such as credentials, codec and keepalive parameters, etc. // A ServerOption sets options such as credentials, codec and keepalive parameters, etc.
type ServerOption func(*options) type ServerOption func(*options)
@ -187,23 +190,23 @@ func RPCDecompressor(dc Decompressor) ServerOption {
} }
} }
// MaxMsgSize returns a ServerOption to set the max message size in bytes for inbound mesages. // MaxMsgSize returns a ServerOption to set the max message size in bytes the server can receive.
// If this is not set, gRPC uses the default limit. Deprecated: use MaxReceiveMessageSize instead. // If this is not set, gRPC uses the default limit. Deprecated: use MaxRecvMsgSize instead.
func MaxMsgSize(m int) ServerOption { func MaxMsgSize(m int) ServerOption {
return MaxReceiveMessageSize(m) return MaxRecvMsgSize(m)
} }
// MaxReceiveMessageSize returns a ServerOption to set the max message size in bytes for inbound mesages. // MaxRecvMsgSize returns a ServerOption to set the max message size in bytes the server can receive.
// If this is not set, gRPC uses the default 4MB. // If this is not set, gRPC uses the default 4MB.
func MaxReceiveMessageSize(m int) ServerOption { func MaxRecvMsgSize(m int) ServerOption {
return func(o *options) { return func(o *options) {
o.maxReceiveMessageSize = m o.maxReceiveMessageSize = m
} }
} }
// MaxSendMessageSize returns a ServerOption to set the max message size in bytes for outbound mesages. // MaxSendMsgSize returns a ServerOption to set the max message size in bytes the server can send.
// If this is not set, gRPC uses the default 4MB. // If this is not set, gRPC uses the default 4MB.
func MaxSendMessageSize(m int) ServerOption { func MaxSendMsgSize(m int) ServerOption {
return func(o *options) { return func(o *options) {
o.maxSendMessageSize = m o.maxSendMessageSize = m
} }
@ -669,7 +672,7 @@ func (s *Server) sendResponse(t transport.ServerTransport, stream *transport.Str
grpclog.Fatalf("grpc: Server failed to encode response %v", err) grpclog.Fatalf("grpc: Server failed to encode response %v", err)
} }
if len(p) > s.opts.maxSendMessageSize { if len(p) > s.opts.maxSendMessageSize {
return status.Errorf(codes.ResourceExhausted, "Sent message larger than max (%d vs. %d)", len(p), s.opts.maxSendMessageSize) return status.Errorf(codes.ResourceExhausted, "grpc: trying to send message larger than max (%d vs. %d)", len(p), s.opts.maxSendMessageSize)
} }
err = t.Write(stream, p, opts) err = t.Write(stream, p, opts)
if err == nil && outPayload != nil { if err == nil && outPayload != nil {
@ -773,7 +776,7 @@ func (s *Server) processUnaryRPC(t transport.ServerTransport, stream *transport.
if len(req) > s.opts.maxReceiveMessageSize { if len(req) > s.opts.maxReceiveMessageSize {
// TODO: Revisit the error code. Currently keep it consistent with // TODO: Revisit the error code. Currently keep it consistent with
// java implementation. // java implementation.
return status.Errorf(codes.ResourceExhausted, "Received message larger than max (%d vs. %d)", len(req), s.opts.maxReceiveMessageSize) return status.Errorf(codes.ResourceExhausted, "grpc: received message larger than max (%d vs. %d)", len(req), s.opts.maxReceiveMessageSize)
} }
if err := s.opts.codec.Unmarshal(req, v); err != nil { if err := s.opts.codec.Unmarshal(req, v); err != nil {
return status.Errorf(codes.Internal, "grpc: error unmarshalling request: %v", err) return status.Errorf(codes.Internal, "grpc: error unmarshalling request: %v", err)

View File

@ -371,7 +371,7 @@ func (cs *clientStream) SendMsg(m interface{}) (err error) {
return Errorf(codes.Internal, "callInfo maxSendMessageSize field uninitialized(nil)") return Errorf(codes.Internal, "callInfo maxSendMessageSize field uninitialized(nil)")
} }
if len(out) > *cs.c.maxSendMessageSize { if len(out) > *cs.c.maxSendMessageSize {
return Errorf(codes.ResourceExhausted, "Sent message larger than max (%d vs. %d)", len(out), *cs.c.maxSendMessageSize) return Errorf(codes.ResourceExhausted, "trying to send message larger than max (%d vs. %d)", len(out), *cs.c.maxSendMessageSize)
} }
err = cs.t.Write(cs.s, out, &transport.Options{Last: false}) err = cs.t.Write(cs.s, out, &transport.Options{Last: false})
if err == nil && outPayload != nil { if err == nil && outPayload != nil {
@ -613,7 +613,7 @@ func (ss *serverStream) SendMsg(m interface{}) (err error) {
return err return err
} }
if len(out) > ss.maxSendMessageSize { if len(out) > ss.maxSendMessageSize {
return Errorf(codes.ResourceExhausted, "Sent message larger than max (%d vs. %d)", len(out), ss.maxSendMessageSize) return Errorf(codes.ResourceExhausted, "trying to send message larger than max (%d vs. %d)", len(out), ss.maxSendMessageSize)
} }
if err := ss.t.Write(ss.s, out, &transport.Options{Last: false}); err != nil { if err := ss.t.Write(ss.s, out, &transport.Options{Last: false}); err != nil {
return toRPCErr(err) return toRPCErr(err)

View File

@ -504,10 +504,10 @@ func (te *test) startServer(ts testpb.TestServiceServer) {
sopts = append(sopts, grpc.MaxMsgSize(*te.maxMsgSize)) sopts = append(sopts, grpc.MaxMsgSize(*te.maxMsgSize))
} }
if te.maxServerReceiveMsgSize != nil { if te.maxServerReceiveMsgSize != nil {
sopts = append(sopts, grpc.MaxReceiveMessageSize(*te.maxServerReceiveMsgSize)) sopts = append(sopts, grpc.MaxRecvMsgSize(*te.maxServerReceiveMsgSize))
} }
if te.maxServerSendMsgSize != nil { if te.maxServerSendMsgSize != nil {
sopts = append(sopts, grpc.MaxSendMessageSize(*te.maxServerSendMsgSize)) sopts = append(sopts, grpc.MaxSendMsgSize(*te.maxServerSendMsgSize))
} }
if te.tapHandle != nil { if te.tapHandle != nil {
sopts = append(sopts, grpc.InTapHandle(te.tapHandle)) sopts = append(sopts, grpc.InTapHandle(te.tapHandle))
@ -610,10 +610,10 @@ func (te *test) clientConn() *grpc.ClientConn {
opts = append(opts, grpc.WithMaxMsgSize(*te.maxMsgSize)) opts = append(opts, grpc.WithMaxMsgSize(*te.maxMsgSize))
} }
if te.maxClientReceiveMsgSize != nil { if te.maxClientReceiveMsgSize != nil {
opts = append(opts, grpc.WithDefaultCallOptions(grpc.WithMaxReceiveMessageSize(*te.maxClientReceiveMsgSize))) opts = append(opts, grpc.WithDefaultCallOptions(grpc.MaxCallRecvMsgSize(*te.maxClientReceiveMsgSize)))
} }
if te.maxClientSendMsgSize != nil { if te.maxClientSendMsgSize != nil {
opts = append(opts, grpc.WithDefaultCallOptions(grpc.WithMaxSendMessageSize(*te.maxClientSendMsgSize))) opts = append(opts, grpc.WithDefaultCallOptions(grpc.MaxCallSendMsgSize(*te.maxClientSendMsgSize)))
} }
switch te.e.security { switch te.e.security {
case "tls": case "tls":