MCPcopy Create free account
hub / github.com/apache/brpc / ConvertGrpcTimeoutToUS

Function ConvertGrpcTimeoutToUS

src/brpc/grpc.cpp:172–207  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

170}
171
172int64_t ConvertGrpcTimeoutToUS(const std::string* grpc_timeout) {
173 if (!grpc_timeout || grpc_timeout->empty()) {
174 return -1;
175 }
176 char* endptr = NULL;
177 int64_t timeout_value = (int64_t)strtol(grpc_timeout->data(), &endptr, 10);
178 // Only the format that the digit number is equal to (timeout header size - 1)
179 // is valid. Otherwise the format is not valid and is treated as no deadline.
180 // For example:
181 // "1H", "2993S", "82m" is valid.
182 // "30A" is also valid, but the following switch would fall into default
183 // case and return -1 since 'A' is not a valid time unit.
184 // "123ASH" is not vaid since the digit number is 3, while the size is 6.
185 // "HHH" is not valid since the dight number is 0, while the size is 3.
186 if ((size_t)(endptr - grpc_timeout->data()) != grpc_timeout->size() - 1) {
187 return -1;
188 }
189 switch (*endptr) {
190 case 'H':
191 return timeout_value * 3600 * 1000000;
192 case 'M':
193 return timeout_value * 60 * 1000000;
194 case 'S':
195 return timeout_value * 1000000;
196 case 'm':
197 return timeout_value * 1000;
198 case 'u':
199 return timeout_value;
200 case 'n':
201 timeout_value = (timeout_value + 500) / 1000;
202 return (timeout_value == 0) ? 1 : timeout_value;
203 default:
204 return -1;
205 }
206 CHECK(false) << "Impossible";
207}
208
209} // namespace brpc

Callers 1

ProcessHttpRequestFunction · 0.85

Calls 3

emptyMethod · 0.45
dataMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected