Software /
code /
prosody
Comparison
net/server_epoll.lua @ 7563:71dc0d89a9b8
net.server_epoll: Wrap calling of ondisconnect listener in additional indirection
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Sun, 14 Aug 2016 01:09:55 +0200 |
parent | 7560:785fa1138293 |
child | 7564:f95ffd24e042 |
comparison
equal
deleted
inserted
replaced
7562:bc40f6d626a0 | 7563:71dc0d89a9b8 |
---|---|
153 else | 153 else |
154 self._readtimeout = addtimer(t, function () | 154 self._readtimeout = addtimer(t, function () |
155 if self:onreadtimeout() then | 155 if self:onreadtimeout() then |
156 return cfg.read_timeout; | 156 return cfg.read_timeout; |
157 else | 157 else |
158 self.listeners.ondisconnect(self, "read timeout"); | 158 self:ondisconnect("read timeout"); |
159 self:destroy(); | 159 self:destroy(); |
160 end | 160 end |
161 end); | 161 end); |
162 end | 162 end |
163 end | 163 end |
328 self._starttls = true; | 328 self._starttls = true; |
329 else | 329 else |
330 self:setflags(false, false); | 330 self:setflags(false, false); |
331 local conn, err = luasec.wrap(self.conn, ctx or self.tls); | 331 local conn, err = luasec.wrap(self.conn, ctx or self.tls); |
332 if not conn then | 332 if not conn then |
333 self.listeners.ondisconnect(self, err); | 333 self:ondisconnect(err); |
334 self:destroy(); | 334 self:destroy(); |
335 end | 335 end |
336 conn:settimeout(0); | 336 conn:settimeout(0); |
337 self.conn = conn; | 337 self.conn = conn; |
338 self._starttls = nil; | 338 self._starttls = nil; |
363 elseif err == "wantwrite" then | 363 elseif err == "wantwrite" then |
364 self:setflags(false, true); | 364 self:setflags(false, true); |
365 self:setreadtimeout(false); | 365 self:setreadtimeout(false); |
366 self:setwritetimeout(cfg.handshake_timeout); | 366 self:setwritetimeout(cfg.handshake_timeout); |
367 else | 367 else |
368 self.listeners.ondisconnect(self, err); | 368 self:ondisconnect(err); |
369 self:destroy(); | 369 self:destroy(); |
370 end | 370 end |
371 end | 371 end |
372 | 372 |
373 local function wrapsocket(client, server, pattern, listeners, tls) -- luasocket object -> interface object | 373 local function wrapsocket(client, server, pattern, listeners, tls) -- luasocket object -> interface object |
428 self:onreadable(); | 428 self:onreadable(); |
429 end | 429 end |
430 end); | 430 end); |
431 end | 431 end |
432 | 432 |
433 function interface:ondisconnect(err) | |
434 if self.listeners.ondisconnect then | |
435 self.listeners.ondisconnect(self, err); | |
436 end | |
437 end | |
438 | |
433 function interface:onconnect() | 439 function interface:onconnect() |
434 self.onwriteable = nil; | 440 self.onwriteable = nil; |
435 self.listeners.onconnect(self); | 441 if self.listeners.onconnect then |
442 self.listeners.onconnect(self); | |
443 end | |
436 self:setflags(true); | 444 self:setflags(true); |
437 return self:onwriteable(); | 445 return self:onwriteable(); |
438 end | 446 end |
439 | 447 |
440 local function addserver(addr, port, listeners, pattern, tls) | 448 local function addserver(addr, port, listeners, pattern, tls) |