trpc.group/trpc-go/trpc-go@v1.0.3/stream/config.go (about) 1 // 2 // 3 // Tencent is pleased to support the open source community by making tRPC available. 4 // 5 // Copyright (C) 2023 THL A29 Limited, a Tencent company. 6 // All rights reserved. 7 // 8 // If you have downloaded a copy of the tRPC source code from Tencent, 9 // please note that tRPC source code is licensed under the Apache 2.0 License, 10 // A copy of the Apache 2.0 License is included in this file. 11 // 12 // 13 14 package stream 15 16 import "math" 17 18 // define common error strings. 19 const ( 20 // can't find this address. 21 noSuchAddr string = "no such addr" 22 // Couldn't find the stream ID. 23 noSuchStreamID string = "no such stream ID" 24 // send Close frame error. 25 closeSendFail string = "stream: CloseSend fail" 26 // stream has been closed. 27 streamClosed string = "stream is already closed" 28 // unknown frame type. 29 unknownFrameType string = "unknown frame type" 30 // ServerStreamTransport not implemented. 31 streamTransportUnimplemented string = "server StreamTransport is not implemented" 32 // msg does not contain FrameHead. 33 frameHeadNotInMsg string = "frameHead is not contained in msg" 34 // frameHead is invalid, not trpc FrameHead. 35 frameHeadInvalid string = "frameHead is invalid" 36 // streamFrameInvalid streaming frame type assertion error. 37 streamFrameInvalid string = "stream frame assert failed" 38 // responseInvalid response type assertion error. 39 responseInvalid string = "value type is not response" 40 ) 41 42 const ( 43 // maxInitWindowSize maximum initial window size. 44 maxInitWindowSize uint32 = math.MaxUint32 45 // defaultInitwindowSize default initialization window size. 46 defaultInitWindowSize uint32 = 65535 47 ) 48 49 // response contains the received message, including data []byte part and error. 50 type response struct { 51 data []byte 52 err error 53 } 54 55 // getWindowSize gets the window size through the configured parameters. 56 func getWindowSize(s uint32) uint32 { 57 if s <= defaultInitWindowSize { 58 return defaultInitWindowSize 59 } 60 if s >= maxInitWindowSize { 61 return maxInitWindowSize 62 } 63 return s 64 }