aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKim Alvefur <zash@zash.se>2016-08-18 16:59:31 +0200
committerKim Alvefur <zash@zash.se>2016-08-18 16:59:31 +0200
commit9f8d0b3e950e0365a75e708c7f7f5cb474183ecf (patch)
tree36e4252dcf027527c7bc4fcaba866caeaa644790
parent86989d47bc2aacd7889dbb8d93c31486177238e2 (diff)
downloadprosody-9f8d0b3e950e0365a75e708c7f7f5cb474183ecf.tar.gz
prosody-9f8d0b3e950e0365a75e708c7f7f5cb474183ecf.zip
net.server_epoll: Refactor to use common initialization
-rw-r--r--net/server_epoll.lua40
1 files changed, 16 insertions, 24 deletions
diff --git a/net/server_epoll.lua b/net/server_epoll.lua
index 89ac4f4d..15c39ae8 100644
--- a/net/server_epoll.lua
+++ b/net/server_epoll.lua
@@ -453,13 +453,17 @@ function interface:onacceptable()
end
local client = wrapsocket(conn, self, nil, self.listeners, self.tls);
log("debug", "New connection %s", tostring(client));
- if self.tls then
- client._tls = false;
- client:starttls();
+ client:init();
+end
+
+function interface:init()
+ if self.tls and not self._tls then
+ self._tls = false; -- This means we should call onconnect when TLS is up
+ return self:starttls();
else
- client:setflags(false, true);
+ self:setflags(false, true);
end
- client:setreadtimeout();
+ self:setreadtimeout();
end
function interface:pause()
@@ -513,18 +517,11 @@ end
-- COMPAT
local function wrapclient(conn, addr, port, listeners, pattern, tls)
- local client = setmetatable({
- conn = conn;
- created = gettime();
- listeners = listeners;
- _pattern = pattern;
- writebuffer = {};
- tls = tls;
- onwriteable = interface.onconnect;
- peer = { addr, port };
- }, interface_mt);
- fds[client:getfd()] = client;
- client:setflags(false, true);
+ local client = wrapsocket(conn, nil, pattern, listeners, tls);
+ if not client.peername then
+ client.peername, client.peerport = addr, port;
+ end
+ client:init();
return client;
end
@@ -533,13 +530,8 @@ local function addclient(addr, port, listeners, pattern, tls)
if not conn then return conn, err; end
conn:settimeout(0);
conn:connect(addr, port);
- local client = wrapclient(conn, addr, port, listeners, pattern, tls);
- if tls then
- client._tls = false;
- client:starttls();
- else
- client:setflags(true, true);
- end
+ local client = wrapsocket(conn, nil, pattern, listeners, tls)
+ client:init();
return client, conn;
end