Software /
code /
prosody
Comparison
net/server_epoll.lua @ 7597:cd34aa6b1632
net.server_epoll: Refactor to use common initialization
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Thu, 18 Aug 2016 16:59:31 +0200 |
parent | 7596:2c4ba55b616c |
child | 7598:335b5ce06062 |
comparison
equal
deleted
inserted
replaced
7596:2c4ba55b616c | 7597:cd34aa6b1632 |
---|---|
451 self:pausefor(cfg.accept_retry_interval); | 451 self:pausefor(cfg.accept_retry_interval); |
452 return; | 452 return; |
453 end | 453 end |
454 local client = wrapsocket(conn, self, nil, self.listeners, self.tls); | 454 local client = wrapsocket(conn, self, nil, self.listeners, self.tls); |
455 log("debug", "New connection %s", tostring(client)); | 455 log("debug", "New connection %s", tostring(client)); |
456 if self.tls then | 456 client:init(); |
457 client._tls = false; | 457 end |
458 client:starttls(); | 458 |
459 else | 459 function interface:init() |
460 client:setflags(false, true); | 460 if self.tls and not self._tls then |
461 end | 461 self._tls = false; -- This means we should call onconnect when TLS is up |
462 client:setreadtimeout(); | 462 return self:starttls(); |
463 else | |
464 self:setflags(false, true); | |
465 end | |
466 self:setreadtimeout(); | |
463 end | 467 end |
464 | 468 |
465 function interface:pause() | 469 function interface:pause() |
466 self:setflags(false); | 470 self:setflags(false); |
467 end | 471 end |
511 return server; | 515 return server; |
512 end | 516 end |
513 | 517 |
514 -- COMPAT | 518 -- COMPAT |
515 local function wrapclient(conn, addr, port, listeners, pattern, tls) | 519 local function wrapclient(conn, addr, port, listeners, pattern, tls) |
516 local client = setmetatable({ | 520 local client = wrapsocket(conn, nil, pattern, listeners, tls); |
517 conn = conn; | 521 if not client.peername then |
518 created = gettime(); | 522 client.peername, client.peerport = addr, port; |
519 listeners = listeners; | 523 end |
520 _pattern = pattern; | 524 client:init(); |
521 writebuffer = {}; | |
522 tls = tls; | |
523 onwriteable = interface.onconnect; | |
524 peer = { addr, port }; | |
525 }, interface_mt); | |
526 fds[client:getfd()] = client; | |
527 client:setflags(false, true); | |
528 return client; | 525 return client; |
529 end | 526 end |
530 | 527 |
531 local function addclient(addr, port, listeners, pattern, tls) | 528 local function addclient(addr, port, listeners, pattern, tls) |
532 local conn, err = socket.tcp(); | 529 local conn, err = socket.tcp(); |
533 if not conn then return conn, err; end | 530 if not conn then return conn, err; end |
534 conn:settimeout(0); | 531 conn:settimeout(0); |
535 conn:connect(addr, port); | 532 conn:connect(addr, port); |
536 local client = wrapclient(conn, addr, port, listeners, pattern, tls); | 533 local client = wrapsocket(conn, nil, pattern, listeners, tls) |
537 if tls then | 534 client:init(); |
538 client._tls = false; | |
539 client:starttls(); | |
540 else | |
541 client:setflags(true, true); | |
542 end | |
543 return client, conn; | 535 return client, conn; |
544 end | 536 end |
545 | 537 |
546 local function link(from, to) | 538 local function link(from, to) |
547 from.listeners = setmetatable({ | 539 from.listeners = setmetatable({ |