MCPcopy Create free account
hub / github.com/apache/thrift / getPeerHost

Method getPeerHost

lib/cpp/src/thrift/transport/TSocket.cpp:852–888  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

850}
851
852std::string TSocket::getPeerHost() const {
853 if (peerHost_.empty() && !isUnixDomainSocket()) {
854 struct sockaddr_storage addr;
855 struct sockaddr* addrPtr;
856 socklen_t addrLen;
857
858 if (socket_ == THRIFT_INVALID_SOCKET) {
859 return host_;
860 }
861
862 addrPtr = getCachedAddress(&addrLen);
863
864 if (addrPtr == nullptr) {
865 addrLen = sizeof(addr);
866 if (getpeername(socket_, (sockaddr*)&addr, &addrLen) != 0) {
867 return peerHost_;
868 }
869 addrPtr = (sockaddr*)&addr;
870
871 const_cast<TSocket&>(*this).setCachedAddress(addrPtr, addrLen);
872 }
873
874 char clienthost[NI_MAXHOST];
875 char clientservice[NI_MAXSERV];
876
877 getnameinfo((sockaddr*)addrPtr,
878 addrLen,
879 clienthost,
880 sizeof(clienthost),
881 clientservice,
882 sizeof(clientservice),
883 0);
884
885 peerHost_ = clienthost;
886 }
887 return peerHost_;
888}
889
890std::string TSocket::getPeerAddress() const {
891 if (peerAddress_.empty() && !isUnixDomainSocket()) {

Callers 1

getHandlerMethod · 0.80

Calls 2

emptyMethod · 0.80
setCachedAddressMethod · 0.80

Tested by

no test coverage detected