From 47963b59da90be2d851ae873f3d5ba8796f786b9 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Wed, 26 Sep 2018 13:53:18 +0200 Subject: net.server_epoll: Factor out IP/port detection into its own method --- net/server_epoll.lua | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'net') diff --git a/net/server_epoll.lua b/net/server_epoll.lua index cd91fce0..9751fa45 100644 --- a/net/server_epoll.lua +++ b/net/server_epoll.lua @@ -501,15 +501,20 @@ local function wrapsocket(client, server, read_size, listeners, tls_ctx) -- luas tls_ctx = tls_ctx; }, interface_mt); - local ok, peername, peerport = pcall(client.getpeername, client); + conn:updatenames(); + return conn; +end + +function interface:updatenames() + local conn = self.conn; + local ok, peername, peerport = pcall(conn.getpeername, conn); if ok then - conn.peername, conn.peerport = peername, peerport; + self.peername, self.peerport = peername, peerport; end - local ok, sockname, sockport = pcall(client.getsockname, client); + local ok, sockname, sockport = pcall(conn.getsockname, conn); if ok then - conn.sockname, conn.sockport = sockname, sockport; + self.sockname, self.sockport = sockname, sockport; end - return conn; end -- A server interface has new incoming connections waiting -- cgit v1.2.3