Mercurial > prosody-hg
comparison net/connect.lua @ 10623:f51c88baeb8a
Backed out changeset 44ef46e1a951 (not optimal API)
| author | Matthew Wild <mwild1@gmail.com> |
|---|---|
| date | Sat, 25 Jan 2020 14:25:29 +0000 |
| parents | 44ef46e1a951 |
| children | 2edb72ef312a |
comparison
equal
deleted
inserted
replaced
| 10622:0662fe0e2c31 | 10623:f51c88baeb8a |
|---|---|
| 1 local server = require "net.server"; | 1 local server = require "net.server"; |
| 2 local log = require "util.logger".init("net.connect"); | 2 local log = require "util.logger".init("net.connect"); |
| 3 local new_id = require "util.id".short; | 3 local new_id = require "util.id".short; |
| 4 | 4 |
| 5 -- TODO Respect use_ipv4, use_ipv6 | |
| 5 -- TODO #1246 Happy Eyeballs | 6 -- TODO #1246 Happy Eyeballs |
| 6 -- FIXME RFC 6724 | 7 -- FIXME RFC 6724 |
| 7 -- FIXME Error propagation from resolvers doesn't work | 8 -- FIXME Error propagation from resolvers doesn't work |
| 8 -- FIXME #1428 Reuse DNS resolver object between service and basic resolver | 9 -- FIXME #1428 Reuse DNS resolver object between service and basic resolver |
| 9 -- FIXME #1429 Close DNS resolver object when done | 10 -- FIXME #1429 Close DNS resolver object when done |
| 10 | |
| 11 local default_connector_options = { | |
| 12 use_ipv4 = true; | |
| 13 use_ipv6 = true; | |
| 14 }; | |
| 15 | 11 |
| 16 local pending_connection_methods = {}; | 12 local pending_connection_methods = {}; |
| 17 local pending_connection_mt = { | 13 local pending_connection_mt = { |
| 18 __name = "pending_connection"; | 14 __name = "pending_connection"; |
| 19 __index = pending_connection_methods; | 15 __index = pending_connection_methods; |
| 80 p.last_error = reason or "unknown reason"; | 76 p.last_error = reason or "unknown reason"; |
| 81 p:log("debug", "Connection attempt failed: %s", p.last_error); | 77 p:log("debug", "Connection attempt failed: %s", p.last_error); |
| 82 attempt_connection(p); | 78 attempt_connection(p); |
| 83 end | 79 end |
| 84 | 80 |
| 85 local function new_connector(connector_options) | 81 local function connect(target_resolver, listeners, options, data) |
| 86 local function connect(target_resolver, listeners, options, data) | 82 local p = setmetatable({ |
| 87 local p = setmetatable({ | 83 id = new_id(); |
| 88 id = new_id(); | 84 target_resolver = target_resolver; |
| 89 target_resolver = target_resolver; | 85 listeners = assert(listeners); |
| 90 listeners = assert(listeners); | 86 options = options or {}; |
| 91 options = options or {}; | 87 data = data; |
| 92 data = data; | 88 }, pending_connection_mt); |
| 93 connector_options = connector_options or default_connector_options; | |
| 94 }, pending_connection_mt); | |
| 95 | 89 |
| 96 p:log("debug", "Starting connection process"); | 90 p:log("debug", "Starting connection process"); |
| 97 attempt_connection(p); | 91 attempt_connection(p); |
| 98 end | |
| 99 return connect; | |
| 100 end | 92 end |
| 101 | 93 |
| 102 return { | 94 return { |
| 103 connect = new_connector(default_connector_options); | 95 connect = connect; |
| 104 new_connector = new_connector; | |
| 105 }; | 96 }; |
