MCPcopy Create free account
hub / github.com/Tencent/phxsql / SendProxyHeader

Method SendProxyHeader

phxsqlproxy/proxy_protocol_handler.cpp:264–289  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

262}
263
264int ProxyProtocolHandler::SendProxyHeader(int fd) {
265 int ret = 0;
266 std::string header;
267 switch (config_->ProxyProtocol()) {
268 case 0:
269 return 0;
270 case 1:
271 ret = MakeProxyHeaderV1(header);
272 break;
273 case 2:
274 ret = MakeProxyHeaderV2(header);
275 break;
276 default:
277 return -__LINE__;
278 }
279
280 while (ret == 0) {
281 ret = RoutineWriteWithTimeout(fd, header.c_str(), header.size(), config_->WriteTimeoutMs());
282 if (ret != 0 && ret != (int) header.size()) {
283 LOG_ERR("write header to fd [%d] failed, ret %d, hdr size %zu", fd, ret, header.size());
284 return -__LINE__;
285 }
286 }
287
288 return ret;
289}
290
291int ProxyProtocolHandler::MakeProxyHeaderV1(std::string & header) {
292 if (src_addr_.ss_family == AF_INET && dst_addr_.ss_family == AF_INET) {

Callers 1

runMethod · 0.80

Calls 3

RoutineWriteWithTimeoutFunction · 0.85
ProxyProtocolMethod · 0.80
WriteTimeoutMsMethod · 0.80

Tested by

no test coverage detected