diff options
author | Kim Alvefur <zash@zash.se> | 2016-08-18 15:55:50 +0200 |
---|---|---|
committer | Kim Alvefur <zash@zash.se> | 2016-08-18 15:55:50 +0200 |
commit | 57511e200f68478411fdb79f836f87085cf4d33d (patch) | |
tree | 2b50d4a4984da950fab9b61f8422aac06b8ff5ca | |
parent | 45dd41e2348d37a2d5edee72323f3305fd6e34d7 (diff) | |
download | prosody-57511e200f68478411fdb79f836f87085cf4d33d.tar.gz prosody-57511e200f68478411fdb79f836f87085cf4d33d.zip |
net.server_epoll: Collect and expose local and remote address and ports
-rw-r--r-- | net/server_epoll.lua | 30 |
1 files changed, 25 insertions, 5 deletions
diff --git a/net/server_epoll.lua b/net/server_epoll.lua index 9b613c3f..d661d53a 100644 --- a/net/server_epoll.lua +++ b/net/server_epoll.lua @@ -114,11 +114,11 @@ local interface = {}; local interface_mt = { __index = interface }; function interface_mt:__tostring() - if self.peer then + if self.peername then if self.conn then return ("%d %s [%s]:%d"):format(self:getfd(), tostring(self.conn), self.peer[1], self.peer[2]); else - return ("%d [%s]:%d"):format(self:getfd(), self.peer[1], self.peer[2]); + return ("%d [%s]:%d"):format(self:getfd(), self.peername, self.peerport); end end return tostring(self:getfd()); @@ -147,7 +147,23 @@ function interface:getfd() end function interface:ip() - return self.peer[1]; + return self.peername or self.sockname; +end + +function interface:port() + return self.sockport or self.peerport; +end + +function interface:clientport() + return self.sockport; +end + +function interface:serverport() + if self.sockport then + return self.sockport; + elseif self.server then + self.server:port(); + end end function interface:socket() @@ -396,7 +412,10 @@ local function wrapsocket(client, server, pattern, listeners, tls) -- luasocket tls = tls; }, interface_mt); if client.getpeername then - conn.peer = {client:getpeername()} + conn.peername, conn.peerport = client:getpeername(); + end + if client.getsockname then + conn.sockname, conn.sockport = client:getsockname(); end fds[conn:getfd()] = conn; @@ -461,7 +480,8 @@ local function addserver(addr, port, listeners, pattern, tls) _pattern = pattern; onreadable = interface.onacceptable; tls = tls; - peer = { addr, port }; + sockname = addr; + sockport = port; }, interface_mt); server:setflags(true, false); fds[server:getfd()] = server; |