Software /
code /
prosody
Comparison
net/adns.lua @ 6780:647adfd8f738
net.*: Remove use of module() function
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Sat, 21 Feb 2015 10:45:24 +0100 |
parent | 6510:8273236a995f |
child | 7475:ee878fa78b8b |
comparison
equal
deleted
inserted
replaced
6779:6236668da30a | 6780:647adfd8f738 |
---|---|
14 local t_insert, t_remove = table.insert, table.remove; | 14 local t_insert, t_remove = table.insert, table.remove; |
15 local coroutine, tostring, pcall = coroutine, tostring, pcall; | 15 local coroutine, tostring, pcall = coroutine, tostring, pcall; |
16 | 16 |
17 local function dummy_send(sock, data, i, j) return (j-i)+1; end | 17 local function dummy_send(sock, data, i, j) return (j-i)+1; end |
18 | 18 |
19 module "adns" | 19 local _ENV = nil; |
20 | 20 |
21 function lookup(handler, qname, qtype, qclass) | 21 local function lookup(handler, qname, qtype, qclass) |
22 return coroutine.wrap(function (peek) | 22 return coroutine.wrap(function (peek) |
23 if peek then | 23 if peek then |
24 log("debug", "Records for %s already cached, using those...", qname); | 24 log("debug", "Records for %s already cached, using those...", qname); |
25 handler(peek); | 25 handler(peek); |
26 return; | 26 return; |
41 log("error", "Error in DNS response handler: %s", tostring(err)); | 41 log("error", "Error in DNS response handler: %s", tostring(err)); |
42 end | 42 end |
43 end)(dns.peek(qname, qtype, qclass)); | 43 end)(dns.peek(qname, qtype, qclass)); |
44 end | 44 end |
45 | 45 |
46 function cancel(handle, call_handler, reason) | 46 local function cancel(handle, call_handler, reason) |
47 log("warn", "Cancelling DNS lookup for %s", tostring(handle[3])); | 47 log("warn", "Cancelling DNS lookup for %s", tostring(handle[3])); |
48 dns.cancel(handle[1], handle[2], handle[3], handle[4], call_handler); | 48 dns.cancel(handle[1], handle[2], handle[3], handle[4], call_handler); |
49 end | 49 end |
50 | 50 |
51 function new_async_socket(sock, resolver) | 51 local function new_async_socket(sock, resolver) |
52 local peername = "<unknown>"; | 52 local peername = "<unknown>"; |
53 local listener = {}; | 53 local listener = {}; |
54 local handler = {}; | 54 local handler = {}; |
55 local err; | 55 local err; |
56 function listener.onincoming(conn, data) | 56 function listener.onincoming(conn, data) |
86 return handler; | 86 return handler; |
87 end | 87 end |
88 | 88 |
89 dns.socket_wrapper_set(new_async_socket); | 89 dns.socket_wrapper_set(new_async_socket); |
90 | 90 |
91 return _M; | 91 return { |
92 lookup = lookup; | |
93 cancel = cancel; | |
94 new_async_socket = new_async_socket; | |
95 }; |