Skip to content

Commit

Permalink
HPCC-32829 Avoid getPeerEndpoint refetching peer name
Browse files Browse the repository at this point in the history
When a socket is attached the peer is captured in existing
member, reuse them in getPeerEndpoint/getPeerAddress.
This also means that these calls will continue to work
after the socket is closed. Therefore tracing of the peer
on a closed socket will now be valid.

Signed-off-by: Jake Smith <[email protected]>
  • Loading branch information
jakesmith committed Oct 18, 2024
1 parent 09d82ed commit 41ba3c9
Showing 1 changed file with 4 additions and 12 deletions.
16 changes: 4 additions & 12 deletions system/jlib/jsocket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -609,10 +609,10 @@ class CSocket: public ISocket, public CInterface
enum { ss_open, ss_shutdown, ss_close, ss_pre_open } state;
T_SOCKET sock;
// char* hostname; // host address
unsigned short hostport; // host port
unsigned short hostport; // host port (NB: this is the peer port if an attached socket)
unsigned short localPort;
SOCKETMODE sockmode;
IpAddress targetip;
IpAddress targetip; // NB: this is peer if an attached socket
SocketEndpoint returnep; // set by set_return_addr

MCASTREQ * mcastreq;
Expand Down Expand Up @@ -1472,16 +1472,8 @@ SocketEndpoint &CSocket::getPeerEndpoint(SocketEndpoint &ep)
if (sockmode==sm_udp_server) { // udp server
ep.set(returnep);
}
else {
DEFINE_SOCKADDR(u);
socklen_t ul = sizeof(u);
if (::getpeername(sock,&u.sa, &ul)<0) {
DBGLOG("getpeername failed %d",SOCKETERRNO());
ep.set(NULL, 0);
}
else
getSockAddrEndpoint(u,ul,ep);
}
else
ep.set(hostport, targetip); // NB: if this is an attached socket, targetip/hostpost are the peer
return ep;
}

Expand Down

0 comments on commit 41ba3c9

Please sign in to comment.