diff --git a/system/jlib/jsocket.cpp b/system/jlib/jsocket.cpp index 5dfd4acde52..63508ac7979 100644 --- a/system/jlib/jsocket.cpp +++ b/system/jlib/jsocket.cpp @@ -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(); @@ -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; @@ -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); @@ -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 @@ -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 } @@ -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; }