Skip to content

Commit

Permalink
change max message size functions name
Browse files Browse the repository at this point in the history
  • Loading branch information
lyuxuan committed May 19, 2017
1 parent 504db8e commit d19bbe8
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 25 deletions.
2 changes: 1 addition & 1 deletion call.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ func sendRequest(ctx context.Context, dopts dialOptions, compressor Compressor,
return Errorf(codes.Internal, "callInfo maxSendMessageSize field uninitialized(nil)")
}
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)
if err == nil && outPayload != nil {
Expand Down
4 changes: 2 additions & 2 deletions clientconn.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
return WithDefaultCallOptions(WithMaxReceiveMessageSize(s))
return WithDefaultCallOptions(MaxCallRecvMsgSize(s))
}

// WithDefaultCallOptions returns a DialOption which sets the default CallOptions for calls over the connection.
Expand Down
12 changes: 6 additions & 6 deletions rpc_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,16 +219,16 @@ func FailFast(failFast bool) CallOption {
})
}

// WithMaxReceiveMessageSize returns a CallOption which sets the maximum message size the client can receive.
func WithMaxReceiveMessageSize(s int) CallOption {
// MaxCallRecvMsgSize returns a CallOption which sets the maximum message size the client can receive.
func MaxCallRecvMsgSize(s int) CallOption {
return beforeCall(func(o *callInfo) error {
o.maxReceiveMessageSize = &s
return nil
})
}

// WithMaxSendMessageSize returns a CallOption which sets the maximum message size the client can send.
func WithMaxSendMessageSize(s int) CallOption {
// MaxCallSendMsgSize returns a CallOption which sets the maximum message size the client can send.
func MaxCallSendMsgSize(s int) CallOption {
return beforeCall(func(o *callInfo) error {
o.maxSendMessageSize = &s
return nil
Expand Down Expand Up @@ -289,7 +289,7 @@ func (p *parser) recvMsg(maxReceiveMessageSize int) (pf payloadFormat, msg []byt
return pf, nil, nil
}
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
// of making it for each message:
Expand Down Expand Up @@ -393,7 +393,7 @@ func recv(p *parser, c Codec, s *transport.Stream, dc Decompressor, m interface{
if len(d) > maxReceiveMessageSize {
// TODO: Revisit the error code. Currently keep it consistent with java
// 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 {
return Errorf(codes.Internal, "grpc: failed to unmarshal the received message %v", err)
Expand Down
23 changes: 13 additions & 10 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,10 @@ type options struct {
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.
type ServerOption func(*options)
Expand Down Expand Up @@ -187,23 +190,23 @@ func RPCDecompressor(dc Decompressor) ServerOption {
}
}

// MaxMsgSize returns a ServerOption to set the max message size in bytes for inbound mesages.
// If this is not set, gRPC uses the default limit. Deprecated: use MaxReceiveMessageSize instead.
// 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 MaxRecvMsgSize instead.
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.
func MaxReceiveMessageSize(m int) ServerOption {
func MaxRecvMsgSize(m int) ServerOption {
return func(o *options) {
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.
func MaxSendMessageSize(m int) ServerOption {
func MaxSendMsgSize(m int) ServerOption {
return func(o *options) {
o.maxSendMessageSize = m
}
Expand Down Expand Up @@ -669,7 +672,7 @@ func (s *Server) sendResponse(t transport.ServerTransport, stream *transport.Str
grpclog.Fatalf("grpc: Server failed to encode response %v", err)
}
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)
if err == nil && outPayload != nil {
Expand Down Expand Up @@ -773,7 +776,7 @@ func (s *Server) processUnaryRPC(t transport.ServerTransport, stream *transport.
if len(req) > s.opts.maxReceiveMessageSize {
// TODO: Revisit the error code. Currently keep it consistent with
// 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 {
return status.Errorf(codes.Internal, "grpc: error unmarshalling request: %v", err)
Expand Down
4 changes: 2 additions & 2 deletions stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ func (cs *clientStream) SendMsg(m interface{}) (err error) {
return Errorf(codes.Internal, "callInfo maxSendMessageSize field uninitialized(nil)")
}
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})
if err == nil && outPayload != nil {
Expand Down Expand Up @@ -613,7 +613,7 @@ func (ss *serverStream) SendMsg(m interface{}) (err error) {
return err
}
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 {
return toRPCErr(err)
Expand Down
8 changes: 4 additions & 4 deletions test/end2end_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -504,10 +504,10 @@ func (te *test) startServer(ts testpb.TestServiceServer) {
sopts = append(sopts, grpc.MaxMsgSize(*te.maxMsgSize))
}
if te.maxServerReceiveMsgSize != nil {
sopts = append(sopts, grpc.MaxReceiveMessageSize(*te.maxServerReceiveMsgSize))
sopts = append(sopts, grpc.MaxRecvMsgSize(*te.maxServerReceiveMsgSize))
}
if te.maxServerSendMsgSize != nil {
sopts = append(sopts, grpc.MaxSendMessageSize(*te.maxServerSendMsgSize))
sopts = append(sopts, grpc.MaxSendMsgSize(*te.maxServerSendMsgSize))
}
if te.tapHandle != nil {
sopts = append(sopts, grpc.InTapHandle(te.tapHandle))
Expand Down Expand Up @@ -610,10 +610,10 @@ func (te *test) clientConn() *grpc.ClientConn {
opts = append(opts, grpc.WithMaxMsgSize(*te.maxMsgSize))
}
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 {
opts = append(opts, grpc.WithDefaultCallOptions(grpc.WithMaxSendMessageSize(*te.maxClientSendMsgSize)))
opts = append(opts, grpc.WithDefaultCallOptions(grpc.MaxCallSendMsgSize(*te.maxClientSendMsgSize)))
}
switch te.e.security {
case "tls":
Expand Down

0 comments on commit d19bbe8

Please sign in to comment.