Software /
code /
prosody
Comparison
net/server_epoll.lua @ 10861:e12690a37795
net.server_epoll: Add way to start accepting clients on an arbitrary server socket
This adds an escape hatch where things like UNIX sockets can be added.
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Mon, 01 Jun 2020 17:19:08 +0200 |
parent | 10854:472fe13a05f9 |
child | 10982:276f16101d59 |
comparison
equal
deleted
inserted
replaced
10860:934dca972f2c | 10861:e12690a37795 |
---|---|
717 self:debug("Connected (%s)", self); | 717 self:debug("Connected (%s)", self); |
718 self.onconnect = noop; | 718 self.onconnect = noop; |
719 self:on("connect"); | 719 self:on("connect"); |
720 end | 720 end |
721 | 721 |
722 local function listen(addr, port, listeners, config) | 722 local function wrapserver(conn, addr, port, listeners, config) |
723 local conn, err = socket.bind(addr, port, cfg.tcp_backlog); | |
724 if not conn then return conn, err; end | |
725 conn:settimeout(0); | |
726 local server = setmetatable({ | 723 local server = setmetatable({ |
727 conn = conn; | 724 conn = conn; |
728 created = realtime(); | 725 created = realtime(); |
729 listeners = listeners; | 726 listeners = listeners; |
730 read_size = config and config.read_size; | 727 read_size = config and config.read_size; |
737 log = logger.init(("serv%s"):format(new_id())); | 734 log = logger.init(("serv%s"):format(new_id())); |
738 }, interface_mt); | 735 }, interface_mt); |
739 server:debug("Server %s created", server); | 736 server:debug("Server %s created", server); |
740 server:add(true, false); | 737 server:add(true, false); |
741 return server; | 738 return server; |
739 end | |
740 | |
741 local function listen(addr, port, listeners, config) | |
742 local conn, err = socket.bind(addr, port, cfg.tcp_backlog); | |
743 if not conn then return conn, err; end | |
744 conn:settimeout(0); | |
745 return wrapserver(conn, addr, port, listeners, config); | |
742 end | 746 end |
743 | 747 |
744 -- COMPAT | 748 -- COMPAT |
745 local function addserver(addr, port, listeners, read_size, tls_ctx) | 749 local function addserver(addr, port, listeners, read_size, tls_ctx) |
746 return listen(addr, port, listeners, { | 750 return listen(addr, port, listeners, { |
895 listen = listen; | 899 listen = listen; |
896 loop = loop; | 900 loop = loop; |
897 closeall = closeall; | 901 closeall = closeall; |
898 setquitting = setquitting; | 902 setquitting = setquitting; |
899 wrapclient = wrapclient; | 903 wrapclient = wrapclient; |
904 wrapserver = wrapserver; | |
900 watchfd = watchfd; | 905 watchfd = watchfd; |
901 link = link; | 906 link = link; |
902 set_config = function (newconfig) | 907 set_config = function (newconfig) |
903 cfg = setmetatable(newconfig, default_config); | 908 cfg = setmetatable(newconfig, default_config); |
904 end; | 909 end; |