cap max msg size to min(max_int, max_uint32) (#1598)

This commit is contained in:
lyuxuan
2017-10-24 10:20:54 -07:00
committed by GitHub
parent 0d57c57a68
commit 5856538706
3 changed files with 36 additions and 8 deletions

View File

@ -208,17 +208,27 @@ func MaxMsgSize(m int) ServerOption {
// 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.
// Note that the maximum effective value is MaxUint32 due to protocol limitations.
func MaxRecvMsgSize(m int) ServerOption {
return func(o *options) {
o.maxReceiveMessageSize = m
if int64(m) > int64(math.MaxUint32) {
o.maxReceiveMessageSize = math.MaxUint32
} else {
o.maxReceiveMessageSize = m
}
}
}
// 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.
// Note that the maximum effective value is MaxUint32 due to protocol limitations.
func MaxSendMsgSize(m int) ServerOption {
return func(o *options) {
o.maxSendMessageSize = m
if int64(m) > int64(math.MaxUint32) {
o.maxSendMessageSize = math.MaxUint32
} else {
o.maxSendMessageSize = m
}
}
}