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

Method getPeerAddress

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

Source from the content-addressed store, hash-verified

888}
889
890std::string TSocket::getPeerAddress() const {
891 if (peerAddress_.empty() && !isUnixDomainSocket()) {
892 struct sockaddr_storage addr;
893 struct sockaddr* addrPtr;
894 socklen_t addrLen;
895
896 if (socket_ == THRIFT_INVALID_SOCKET) {
897 return peerAddress_;
898 }
899
900 addrPtr = getCachedAddress(&addrLen);
901
902 if (addrPtr == nullptr) {
903 addrLen = sizeof(addr);
904 if (getpeername(socket_, (sockaddr*)&addr, &addrLen) != 0) {
905 return peerAddress_;
906 }
907 addrPtr = (sockaddr*)&addr;
908
909 const_cast<TSocket&>(*this).setCachedAddress(addrPtr, addrLen);
910 }
911
912 char clienthost[NI_MAXHOST];
913 char clientservice[NI_MAXSERV];
914
915 getnameinfo(addrPtr,
916 addrLen,
917 clienthost,
918 sizeof(clienthost),
919 clientservice,
920 sizeof(clientservice),
921 NI_NUMERICHOST | NI_NUMERICSERV);
922
923 peerAddress_ = clienthost;
924 peerPort_ = std::atoi(clientservice);
925 }
926 return peerAddress_;
927}
928
929int TSocket::getPeerPort() const {
930 getPeerAddress();

Callers 1

getHandlerMethod · 0.80

Calls 2

emptyMethod · 0.80
setCachedAddressMethod · 0.80

Tested by

no test coverage detected