From 5fd9fc40070e4b3ae273bd7797610017e930f3d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6nke=20Ludwig?= Date: Fri, 10 Mar 2017 21:06:18 +0100 Subject: [PATCH] Always compute TCPConnection.xxxAddress on demand. Storing the network addresses becomes too expensive with UNIX socket support. --- source/vibe/core/net.d | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/source/vibe/core/net.d b/source/vibe/core/net.d index 3cb64a4..cde32dc 100644 --- a/source/vibe/core/net.d +++ b/source/vibe/core/net.d @@ -448,8 +448,6 @@ struct TCPConnection { bool tcpNoDelay = false; bool keepAlive = false; Duration readTimeout = Duration.max; - NetworkAddress remoteAddress; - NetworkAddress localAddress; string remoteAddressString; } @@ -465,13 +463,6 @@ struct TCPConnection { m_socket = socket; m_context = () @trusted { return &eventDriver.core.userData!Context(socket); } (); m_context.readBuffer.capacity = 4096; - try m_context.remoteAddress = NetworkAddress(remote_address); - catch (Exception e) { logWarn("Failed to get remote address for TCP connection: %s", e.msg); } - scope laddr = new RefAddress(m_context.localAddress.sockAddr, m_context.localAddress.sockAddrMaxLen); - try { - enforce(eventDriver.sockets.getLocalAddress(socket, laddr), "Failed to query socket address."); - m_context.localAddress = NetworkAddress(laddr); - } catch (Exception e) { logWarn("Failed to get local address for TCP connection: %s", e.msg); } } this(this) @@ -494,9 +485,23 @@ struct TCPConnection { @property bool keepAlive() const nothrow { return m_context.keepAlive; } @property void readTimeout(Duration duration) { m_context.readTimeout = duration; } @property Duration readTimeout() const nothrow { return m_context.readTimeout; } - @property string peerAddress() const nothrow { return m_context.remoteAddress.toString(); } - @property NetworkAddress localAddress() const nothrow { return m_context.localAddress; } - @property NetworkAddress remoteAddress() const nothrow { return m_context.remoteAddress; } + @property string peerAddress() const nothrow { return this.remoteAddress.toString(); } + @property NetworkAddress localAddress() const nothrow { + NetworkAddress naddr; + scope addr = new RefAddress(naddr.sockAddr, naddr.sockAddrMaxLen); + try { + enforce(eventDriver.sockets.getLocalAddress(m_socket, addr), "Failed to query socket address."); + } catch (Exception e) { logWarn("Failed to get local address for TCP connection: %s", e.msg); } + return naddr; + } + @property NetworkAddress remoteAddress() const nothrow { + NetworkAddress naddr; + scope addr = new RefAddress(naddr.sockAddr, naddr.sockAddrMaxLen); + try { + enforce(eventDriver.sockets.getRemoteAddress(m_socket, addr), "Failed to query socket address."); + } catch (Exception e) { logWarn("Failed to get remote address for TCP connection: %s", e.msg); } + return naddr; + } @property bool connected() const nothrow { if (m_socket == StreamSocketFD.invalid) return false;