net.*: Remove use of module() function

This commit is contained in:
Kim Alvefur 2015-02-21 10:45:24 +01:00
parent 27265c20e2
commit 69652ea24b
5 changed files with 44 additions and 34 deletions

View file

@ -16,9 +16,9 @@ local coroutine, tostring, pcall = coroutine, tostring, pcall;
local function dummy_send(sock, data, i, j) return (j-i)+1; end local function dummy_send(sock, data, i, j) return (j-i)+1; end
module "adns" local _ENV = nil;
function lookup(handler, qname, qtype, qclass) local function lookup(handler, qname, qtype, qclass)
return coroutine.wrap(function (peek) return coroutine.wrap(function (peek)
if peek then if peek then
log("debug", "Records for %s already cached, using those...", qname); log("debug", "Records for %s already cached, using those...", qname);
@ -43,12 +43,12 @@ function lookup(handler, qname, qtype, qclass)
end)(dns.peek(qname, qtype, qclass)); end)(dns.peek(qname, qtype, qclass));
end end
function cancel(handle, call_handler, reason) local function cancel(handle, call_handler, reason)
log("warn", "Cancelling DNS lookup for %s", tostring(handle[3])); log("warn", "Cancelling DNS lookup for %s", tostring(handle[3]));
dns.cancel(handle[1], handle[2], handle[3], handle[4], call_handler); dns.cancel(handle[1], handle[2], handle[3], handle[4], call_handler);
end end
function new_async_socket(sock, resolver) local function new_async_socket(sock, resolver)
local peername = "<unknown>"; local peername = "<unknown>";
local listener = {}; local listener = {};
local handler = {}; local handler = {};
@ -88,4 +88,8 @@ end
dns.socket_wrapper_set(new_async_socket); dns.socket_wrapper_set(new_async_socket);
return _M; return {
lookup = lookup;
cancel = cancel;
new_async_socket = new_async_socket;
};

View file

@ -2,14 +2,17 @@
local log = require "util.logger".init("net.connlisteners"); local log = require "util.logger".init("net.connlisteners");
local traceback = debug.traceback; local traceback = debug.traceback;
module "httpserver" local _ENV = nil;
function fail() local function fail()
log("error", "Attempt to use legacy connlisteners API. For more info see http://prosody.im/doc/developers/network"); log("error", "Attempt to use legacy connlisteners API. For more info see http://prosody.im/doc/developers/network");
log("error", "Legacy connlisteners API usage, %s", traceback("", 2)); log("error", "Legacy connlisteners API usage, %s", traceback("", 2));
end end
register, deregister = fail, fail; return {
get, start = fail, fail, epic_fail; register = fail;
register = fail;
return _M; get = fail;
start = fail;
-- epic fail
};

View file

@ -71,8 +71,8 @@ local get, set = ztact.get, ztact.set;
local default_timeout = 15; local default_timeout = 15;
-------------------------------------------------- module dns -------------------------------------------------- module dns
module('dns') local _ENV = nil;
local dns = _M; local dns = {};
-- dns type & class codes ------------------------------ dns type & class codes -- dns type & class codes ------------------------------ dns type & class codes

View file

@ -24,7 +24,7 @@ local assert, error = assert, error
local log = require "util.logger".init("http"); local log = require "util.logger".init("http");
module "http" local _ENV = nil;
local requests = {}; -- Open requests local requests = {}; -- Open requests
@ -76,6 +76,13 @@ function listener.ondetach(conn)
requests[conn] = nil; requests[conn] = nil;
end end
local function destroy_request(request)
if request.conn then
request.conn = nil;
request.handler:close()
end
end
local function request_reader(request, data, err) local function request_reader(request, data, err)
if not request.parser then if not request.parser then
local function error_cb(reason) local function error_cb(reason)
@ -107,7 +114,7 @@ local function request_reader(request, data, err)
end end
local function handleerr(err) log("error", "Traceback[http]: %s", traceback(tostring(err), 2)); end local function handleerr(err) log("error", "Traceback[http]: %s", traceback(tostring(err), 2)); end
function request(u, ex, callback) local function request(u, ex, callback)
local req = url.parse(u); local req = url.parse(u);
if not (req and req.host) then if not (req and req.host) then
@ -189,17 +196,12 @@ function request(u, ex, callback)
return req; return req;
end end
function destroy_request(request) return {
if request.conn then request = request;
request.conn = nil;
request.handler:close() -- COMPAT
end urlencode = util_http.urlencode;
end urldecode = util_http.urldecode;
formencode = util_http.formencode;
local urlencode, urldecode = util_http.urlencode, util_http.urldecode; formdecode = util_http.formdecode;
local formencode, formdecode = util_http.formencode, util_http.formdecode; };
_M.urlencode, _M.urldecode = urlencode, urldecode;
_M.formencode, _M.formdecode = formencode, formdecode;
return _M;

View file

@ -2,14 +2,15 @@
local log = require "util.logger".init("net.httpserver"); local log = require "util.logger".init("net.httpserver");
local traceback = debug.traceback; local traceback = debug.traceback;
module "httpserver" local _ENV = nil;
function fail() function fail()
log("error", "Attempt to use legacy HTTP API. For more info see http://prosody.im/doc/developers/legacy_http"); log("error", "Attempt to use legacy HTTP API. For more info see http://prosody.im/doc/developers/legacy_http");
log("error", "Legacy HTTP API usage, %s", traceback("", 2)); log("error", "Legacy HTTP API usage, %s", traceback("", 2));
end end
new, new_from_config = fail, fail; return {
set_default_handler = fail; new = fail;
new_from_config = fail;
return _M; set_default_handler = fail;
};