Skip to content

Commit

Permalink
HPCC-32829 Reuse peerEP from accept when creating socket
Browse files Browse the repository at this point in the history
Signed-off-by: Jake Smith <[email protected]>
  • Loading branch information
jakesmith committed Oct 18, 2024
1 parent d8703d6 commit 8becb08
Showing 1 changed file with 24 additions and 11 deletions.
35 changes: 24 additions & 11 deletions system/jlib/jsocket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -703,7 +703,7 @@ class CSocket: public ISocket, public CInterface
void setTraceName();

CSocket(const SocketEndpoint &_ep,SOCKETMODE smode,const char *name);
CSocket(T_SOCKET new_sock,SOCKETMODE smode,bool _owned);
CSocket(T_SOCKET new_sock,SOCKETMODE smode,bool _owned,SocketEndpoint *_peerEp);

virtual ~CSocket();

Expand Down Expand Up @@ -1254,7 +1254,7 @@ void CSocket::open(int listen_queue_size,bool reuseports)



ISocket* CSocket::accept(bool allowcancel, SocketEndpoint *peerEp)
ISocket* CSocket::accept(bool allowcancel, SocketEndpoint *_peerEp)
{
if ((accept_cancel_state!=accept_not_cancelled) && allowcancel) {
accept_cancel_state=accept_cancelled;
Expand Down Expand Up @@ -1334,10 +1334,12 @@ ISocket* CSocket::accept(bool allowcancel, SocketEndpoint *peerEp)
THROWJSOCKTARGETEXCEPTION(JSOCKERR_cancel_accept);
}

if (peerEp)
getSockAddrEndpoint(peerSockAddr, peerSockAddrLen, *peerEp);
SocketEndpoint peerEp;
getSockAddrEndpoint(peerSockAddr, peerSockAddrLen, peerEp);
if (_peerEp)
*_peerEp = peerEp;

CSocket *ret = new CSocket(newsock,sm_tcp,true);
CSocket *ret = new CSocket(newsock,sm_tcp,true,&peerEp);
ret->checkCfgKeepAlive();
ret->set_inherit(false);
ret->set_nonblock(true);
Expand Down Expand Up @@ -3023,7 +3025,7 @@ CSocket::CSocket(const SocketEndpoint &ep,SOCKETMODE smode,const char *name)
#endif
}

CSocket::CSocket(T_SOCKET new_sock,SOCKETMODE smode,bool _owned)
CSocket::CSocket(T_SOCKET new_sock,SOCKETMODE smode,bool _owned,SocketEndpoint *_peerEp)
{
nonblocking = false;
#ifdef USERECVSEM
Expand All @@ -3045,13 +3047,24 @@ CSocket::CSocket(T_SOCKET new_sock,SOCKETMODE smode,bool _owned)
accept_cancel_state = accept_not_cancelled;
set_nagle(false);
//set_linger(DEFAULT_LINGER_TIME); -- experiment with removing this as closesocket should still endevour to send outstanding data
char peer[256];
hostport = peer_name(peer,sizeof(peer));
targetip.ipset(peer);
if (_peerEp)
{
targetip = *_peerEp;
hostport = _peerEp->port;
}
else
{
char peer[256];
hostport = peer_name(peer,sizeof(peer));
targetip.ipset(peer);
}
SocketEndpoint ep;
localPort = getEndpoint(ep).port;
#ifdef _TRACE
setTraceName("A!", peer);
StringBuffer tmp;
targetip.getIpText(tmp);
tmp.append(":").append(hostport);
setTraceName("A!", tmp);
#endif
}

Expand Down Expand Up @@ -3148,7 +3161,7 @@ ISocket* ISocket::multicast_connect(const SocketEndpoint &ep, unsigned _ttl)

ISocket* ISocket::attach(int s, bool tcpip)
{
CSocket* sock = new CSocket((SOCKET)s, tcpip?sm_tcp:sm_udp, false);
CSocket* sock = new CSocket((SOCKET)s, tcpip?sm_tcp:sm_udp, false, nullptr);
sock->set_nonblock(true);
return sock;
}
Expand Down

0 comments on commit 8becb08

Please sign in to comment.